1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to make my own porgram language

Discussion in 'C' started by aVague, Oct 19, 2007.

  1. aVague

    aVague New Member

    Joined:
    May 2, 2007
    Messages:
    34
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    forex
    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
     
  2. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    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.
     
  3. aVague

    aVague New Member

    Joined:
    May 2, 2007
    Messages:
    34
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    forex
    second, as you guessed
     
  4. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    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: Oct 19, 2007
  5. aVague

    aVague New Member

    Joined:
    May 2, 2007
    Messages:
    34
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    forex
    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
     
  6. aVague

    aVague New Member

    Joined:
    May 2, 2007
    Messages:
    34
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    forex
    I ll try to realize it and show it then
     
  7. aVague

    aVague New Member

    Joined:
    May 2, 2007
    Messages:
    34
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    forex
    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
     

Share This Page