trouble w/assignment

This is a discussion on trouble w/assignment within the C Programming forums, part of the General Programming Boards category; ok, basically i want to be able to input a string and find out if its a valid c identifier.......well, ...

  1. #1
    cereal killer dP munky's Avatar
    Join Date
    Nov 2002
    Posts
    655

    Angry trouble w/assignment

    ok, basically i want to be able to input a string and find out if its a valid c identifier.......well, i got that part to work, the part that just wont come together is when i input ctrl+Z to end the program, it doesnt work???....can canybody help?? THANKS

    //using msvs6.0
    Code:
    #include <stdio.h>
    
    
    
    int StrSpn(char *str, char *cset)
    {
    
    	char *strPTR;
    	char *csetPTR;
    
    	strPTR = str;
    	csetPTR = cset;
    
    	while((*strPTR) != '\0') /* while strPTR != null and != to a space*/
    	{	
    				
    		while((*csetPTR) != '\0' && (*strPTR) != (*csetPTR)) /*whle csetPTR != to null & strPTR != csetPTR*/
    			{
    				csetPTR++; /*increment csetPTR*/
    			}		
    			
    			if ((*strPTR)==(*csetPTR))	/*if strPTR = csetPTR*/
    			{
    				strPTR++;				/*increment strPTR*/
    				csetPTR = cset;			/*reset the value of csetPTR to the value of cset*/
    			}
    			
    			else						/*else, the end of the string is not NULL*/
    			{							/*break the loop*/
    				if((*strPTR) != '\0');
    				{
    					return 3;
    				}
    				break;				
    			}
    
    	}
    	
    	return 0;	
    }
    
    
    int IsDigit(int ch)
    {
    		/*if the value at the first address of the string inputed is a number
    		** the program will print that it is not a valid c identifier and return 0 */
    		if( (ch >='0') && (ch <= '9') )
    			return 0;
    		
    		if (ch == ' ')
    			return 0;
    	
    	return 1;
    }
    
    
    
    int IsIdentifier(char *str)
    {
    	
    	if(str != '\0')
    	{
    		if(StrSpn(str, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789") == '\0') 
    		{						
    			return 1;			/*when strspn gets to the end of the enterd string*/
    								/*and all characters are valid, 1 is returned*/
    		}						
    								
    		else
    		{
    			return 0;			/* if a digit which is not valid is found 0 is returned*/
    			
    		}
    	
    	}
    	return 0;	
    }
    
    
    
    
    
    
    int main()
    {
    	char identifier[255];
    	
    	printf("The purpose of this program is to determine \n");
    	printf("if the string entered is a valid c identifier\n");
    	printf("Press Ctrl Z to exit the program\n");
    	printf("Please Press Enter to Continue.\n");
    
    	while (gets(identifier) != NULL)
    	{
    		printf("Enter an identifier: ");
    		scanf("%[^\n]", identifier);
    		/*Runs the IsDigit function, if the value of*/
    		/*IsDigit returns a zero, end the program*/
    				
    		if(IsDigit(identifier[0]) == 0)
    		{
    			printf("\nThe string is NOT a valid c identifier\n\n");
    		}
    		
    		else if(IsIdentifier(identifier) == 1)
    		{
    			printf("The string is a VALID C IDENTIFIER\n\n");
    		}
    
    		else if(IsIdentifier(identifier) == 0)
    		{
    			printf("The string is NOT a valid c identifier\n\n");
    		
    		
    	}
    	return 0;
    }
    Last edited by dP munky; 11-06-2002 at 01:01 AM.

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Do your own homework digipen boy! Prosona Ghalli isn't going to like this...
    Last edited by MrWizard; 11-06-2002 at 02:30 AM.

  3. #3
    cereal killer dP munky's Avatar
    Join Date
    Nov 2002
    Posts
    655

    woah

    hey there man, i did do my own homework, im not cheating, i just want some direction.....besides, persanna said we could get help!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Trouble with assignment in C
    By mohanlon in forum C Programming
    Replies: 17
    Last Post: 06-23-2009, 11:44 AM
  2. Replies: 6
    Last Post: 01-03-2007, 03:02 PM
  3. Is it so trouble?
    By Yumin in forum Tech Board
    Replies: 4
    Last Post: 01-30-2006, 04:10 PM
  4. trouble scanning in... and link listing
    By panfilero in forum C Programming
    Replies: 14
    Last Post: 11-21-2005, 12:58 PM
  5. C++ program trouble
    By senrab in forum C++ Programming
    Replies: 7
    Last Post: 04-30-2003, 12:55 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21