Thread: language translator (having problems in tokenizing)

  1. #1
    Registered User
    Join Date
    Jun 2008
    Posts
    5

    Exclamation language translator (having problems in tokenizing)

    so this part of the code for mylanguage translator basically, i just started coding tokenzing function.

    the problem: if i put the tokenize function directly into the main or edit the tokenize function so it'll be the main and run it.. it seems to do it's job. But, if i encorporate that function inside the menu function which is called by main... the tokenize function kinda misfires and doesn't correctly displays what it suppose to display. (i'm guessing pointers and all those asterisks.... or if not what?)

    PLEASE HELP.. thanks

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <conio.h>
    
    typedef char string100[101];
    typedef char string50[50];
    
    struct nodeTag{
    	char strInput[31];
    	char strOutput[100][31];
    	struct nodeTag *pNext;
    };
    
    typedef struct nodeTag *ptrNode;
    
    
    void Exit();
    void Menu();
    void Tokenize(ptrNode pStart);
    
    main()
    {
    	Menu();
    }
    void Exit()
    {
    	clrscr();
    }
    
    void Menu(ptrNode pStart)
    {
    	
    	int nSelect, n=1;
    	char cDump;
    
    	do{
    		clrscr();
    		puts("\t\t\t          ___________");
    		puts("\t\t\t         ( MAIN MENU )\n");
    		printf("\t\t\t   --------------------------\n");
    		puts("   \t\t\t   |   SENTENCE TRANSLATOR  |");
    		printf("\t\t\t   --------------------------\n");
    		puts("\t\t\t   [1]  TOKENIZE ");
    		puts("\t\t\t   [2]  ALTERNATE"); 
    		printf("     \t\t\t   --------------------------\n");
    		puts("\t\t\t   |    WORD MANIPULATOR    |"); 
    		printf("     \t\t\t   --------------------------\n");
    		puts("\t\t\t   [3]  ADD WORD ");puts("\t\t\t   [4]  ADD CO-OCCURRING");
    		puts("\t\t\t   [5]  DELETE WORD");puts("\t\t\t   [6]  DELETE CO-OCCURING");
    		puts("\t\t\t   [7]  VIEW WORDS");puts("\t\t\t   [8]  SEARCH WORDS");
    		puts("\t\t\t   [9]  EXPORT");puts("\t\t\t   [10] IMPORT");
    		puts("\t\t\t   [11] EXIT\n\n");printf("\t\t\t         ENTER CHOICE:");
    	
    	    scanf("%d%c",&nSelect,&cDump);
    
    		if (nSelect==1){
    		clrscr();
    		n=0;
    		Tokenize(pStart);
    		}
    		else if (nSelect==2){
    		clrscr();
    		puts("alt");	
    		n=0;
    		}
    		else if (nSelect==3){
    		clrscr();
    		puts("add");	
    		n=0;
    		}
    		else if (nSelect==4){
    		clrscr();
    		puts("addc");	
    		n=0;
    		}
    		else if (nSelect==5){
    		clrscr();
    		puts("del");	
    		n=0;
    		}
    		else if (nSelect==6){
    		clrscr();
    		puts("delc");	
    		n=0;
    		}
    		else if (nSelect==7){
    		clrscr();
    		puts("view");	
    		n=0;
    		}
    		else if (nSelect==8){
    		clrscr();
    		puts("seearch");	
    		n=0;
    		}
    		else if (nSelect==9){
    		Exit();	
    		n=0;
    		}
    		else if (nSelect==10){
    		clrscr();
    		puts("import");
    		n=0;
    		}
    		else if (nSelect==11){
    		n=0;
    		Exit();
    		}
    		
    		else{
    			clrscr();
    			puts("\t\t\t          ___________");
    			puts("\t\t\t         ( MAIN MENU )\n");
    			printf("\t\t\t   --------------------------\n");
    			puts("   \t\t\t   |   SENTENCE TRANSLATOR  |");
    			printf("\t\t\t   --------------------------\n");
    			puts("\t\t\t   [1]  TOKENIZE ");
    			puts("\t\t\t   [2]  ALTERNATE"); 
    			printf("     \t\t\t   --------------------------\n");
    			puts("\t\t\t   |    WORD MANIPULATOR    |"); 
    			printf("     \t\t\t   --------------------------\n");
    			puts("\t\t\t   [3]  ADD WORD ");puts("\t\t\t   [4]  ADD CO-OCCURRING");
    			puts("\t\t\t   [5]  DELETE WORD");puts("\t\t\t   [6]  DELETE CO-OCCURING");
    			puts("\t\t\t   [7]  VIEW WORDS");puts("\t\t\t   [8]  SEARCH WORDS");
    			puts("\t\t\t   [9]  EXPORT");puts("\t\t\t   [10] IMPORT");
    			puts("\t\t\t   [11] EXIT\n\n");printf("\t\t\t         ENTER CHOICE:");
    		
    			scanf("%d",&nSelect);
    		}
    		
    	} while (n!=0);
    	
    }
    
    void Tokenize(ptrNode pStart)	
    {
    	int i=0,sLen;
    	int x=0,y=0,z=0;
    	
    	printf("ENTER TEXT: ");
    	gets(pStart->strInput);
    	sLen=strlen(pStart->strInput);
    		
    	while(i <= sLen && pStart->strInput[x]!= '.')
    	{
    		if(pStart->strInput[x]!=' ')
    		{
    		pStart->strOutput[y][z] = pStart->strInput[x];
    		printf("%c",pStart->strOutput[y][z]);		
    		z++;
    		}
    		else if (pStart->strInput[x]==' ')
    		{
    		z=0;
    		y++;
    		printf(".");
    		}
    		x++;
    		i++;
    	}
    }

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    void Menu();
    void Menu(ptrNode pStart);

    Don't you see any difference here?
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  3. #3
    Registered User
    Join Date
    Jun 2008
    Posts
    5
    piffff.... stupid me... so should that work now?
    XD

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. d programming language - a better c++?
    By kypronite in forum Tech Board
    Replies: 12
    Last Post: 02-28-2011, 02:55 AM
  2. The value of learning a new programming language
    By h3ro in forum General Discussions
    Replies: 21
    Last Post: 06-13-2009, 01:48 AM
  3. ASM to C language
    By TAZIN in forum C Programming
    Replies: 22
    Last Post: 06-03-2009, 06:29 AM
  4. No clue how to make a code to solve problems!
    By ctnzn in forum C Programming
    Replies: 8
    Last Post: 10-16-2008, 02:59 AM
  5. Visual J#
    By mfc2themax in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 10-08-2001, 02:41 PM

Tags for this Thread