How to make my own porgram language

aVague's Avatar, Join Date: May 2007
Go4Expert Member
The problem is , how to write interface to a program

For example , I want to work with a set of points (they have coordinats) , the thing is how concrete can I realize commands .
I compile program , then I start it , write adress of file with points and then write add (4;6) , and this comand should add point with coordinats (4;6) to the file wich adress I wrote
0
DaWei's Avatar, Join Date: Dec 2006
Team Leader
Your question is not clear. I don't think you want to write your own programming language. I think you probably want to use C/C++ to accept number pairs (coordinates) from the user and write them to a file.

You'll need to be clear which of those you want, however.
0
aVague's Avatar, Join Date: May 2007
Go4Expert Member
second, as you guessed
0
DaWei's Avatar, Join Date: Dec 2006
Team Leader
Here's the deal, then.

Open a file for output.

Set up a while loop. Inside the loop, ask the user to enter two numbers. Validate the input and, if correct, write them to the file. Exit the loop on some input condition, such as an empty line.

Close the file.

The particular functions you use for file I/O and for user input will depend on whether or not you are using C or C++. You don't say, and you don't give any indication of your level of expertise.

I would strongly recommend you read this .

Last edited by DaWei; 19Oct2007 at 23:39..
0
aVague's Avatar, Join Date: May 2007
Go4Expert Member
Oh, sorry , I m using C on unix platform , and I am working in Vim.Your advice is clear to me , I ll try to do so , but I want to use commands too. As I suppose , I need to make some functions for that like if to print word "add" and press enter , one of the functions ll be used. How to do that?
Thanks
0
aVague's Avatar, Join Date: May 2007
Go4Expert Member
I ll try to realize it and show it then
0
aVague's Avatar, Join Date: May 2007
Go4Expert Member
so here it is


Code:
#include<stdlib.h>
 #include<stdio.h>
FILE *fp;


 int func_1(int n,double w[],double v[])
  {   int i;
    fp=fopen("in.txt","w+");

    if(fp==NULL) write("can't open");
    return 13;
    
    for(i=0;i<n-1;i++)
    { putchar(w[i]); putchar(v[i]);}

return 7;
    }


void main()
{

  int N,i;
  char z;
  double *oX,*oY;


 printf("what would you like to do now?\n");
 scanf("%s",&z);

switch (z)
{case 'add': printf("\n enter: 1)number of points you wish to add 2)coordinates of points ");
scanf("%d",&N);
oX=(double*)malloc(N*sizeof(double));
oY= (double*)malloc(N*sizeof(double));
for(i=0;i<N-1;i++)
{scanf("%d%d",&oX[i],&oY[i]);printf("\n");i++;}
 func_1(N,oX,oY);
   break;

 case 'q' :break;}
// getchar();
// getchar();
 }


there are some mistakes(in a logic of a program) , I think , help me to find them