String program problem

This is a discussion on String program problem within the C Programming forums, part of the General Programming Boards category; Hi, I got the following program: Code: #include <stdio.h> #define STRINGSIZE 1OO void getString(char *string); void reverseCase(char *string); int numGraph(*string); ...

  1. #1
    Registered User
    Join Date
    Mar 2007
    Posts
    23

    String program problem

    Hi, I got the following program:

    Code:
    #include <stdio.h>
    
    #define STRINGSIZE 1OO
    
    void getString(char *string);
    void reverseCase(char *string);
    int numGraph(*string);
    
    
    int main()
    {
       char string[STRINGSIZE];
       int count;
    
       getString(string);
       printf("Entered string => %s");
    
       count = numGraph(string);
       printf("Number of graphic characters in string = %d\n", count);
    
       reverseCase(string);
       printf("Reverse case   => %s);
    
       return 0;
    }
    
    void reverseCase(char *string)
    {
       /* Reverse the case of all alphabetic characters in the string.
          That is, all upper case characters become lower case and
          all lower case become upper case.
       */
    }
    
    int numGraph(*(string))
    {
       /* Calculate the number of printable graphic characters in the
          string.
       */
    
       int count;
    
       while (string != '\0')
       {
          if (isgraph((int) *string)) count++;
       }
       return count;
    }
    
    void getString(char *string)
    {
       printf("Please enter a string to process\n");
       fgets(string, STRINGSIZE, stdin);
    }
    On this line:
    if (isgraph((int) *string)) count++;
    it gives me a "Illegal statement termination" error. Not sure why that is, anyone got any suggestions because I am not sure on what I m doing wrong.

    Thanks

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,852
    Maybe prototype numGraph() the same as your other two functions.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Duskan please don't double post, especially with different titles...

    Help with string program

  4. #4
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    Code:
    #include <stdio.h>
    #include <ctype.h>
    
    #define STRINGSIZE 100
    /* What are you doing?  'O' and 0 are not the same thing. */
    
    void getString(char *string);
    void reverseCase(char *string);
    int numGraph(char *string);
    
    
    int main()
    {
       char string[STRINGSIZE];
       int count;
    
       getString(string);
       printf("Entered string => %s\n",string);
    
       count = numGraph(string);
       printf("Number of graphic characters in string = %d\n", count);
    
       reverseCase(string);
       printf("Reverse case   => %s\n",string);
    
       return 0;
    }
    
    void reverseCase(char *string)
    {
       /* Reverse the case of all alphabetic characters in the string.
          That is, all upper case characters become lower case and
          all lower case become upper case.
       */
    }
    
    int numGraph(char *string)
    {
       /* Calculate the number of printable graphic characters in the
          string.
       */
    
    	int i,count;
    
    	for(i = 0,count = 0;string[i] != '\0';i++)
    	{
    		if (isgraph((int)string[i])) count++; 
    	}
    	return count;
    }
    
    void getString(char *string)
    {
       printf("Please enter a string to process\n");
       fgets(string, STRINGSIZE, stdin);
    }
    Didn't bother compiling the entire thing, so I can't say for sure that it works, but it should get you on the right track.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Client-server system with input from separate program
    By robot-ic in forum Networking/Device Communication
    Replies: 3
    Last Post: 01-16-2009, 03:30 PM
  2. Inheritance Hierarchy for a Package class
    By twickre in forum C++ Programming
    Replies: 7
    Last Post: 12-08-2007, 04:13 PM
  3. Compile Error that i dont understand
    By bobthebullet990 in forum C++ Programming
    Replies: 5
    Last Post: 05-05-2006, 10:19 AM
  4. Linked List Help
    By CJ7Mudrover in forum C Programming
    Replies: 9
    Last Post: 03-10-2004, 10:33 PM
  5. lvp string...
    By Magma in forum C++ Programming
    Replies: 4
    Last Post: 02-27-2003, 12:03 AM

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