need help with my c program

This is a discussion on need help with my c program within the C Programming forums, part of the General Programming Boards category; i need to make my program here do a palindrome with a word. heres my code. this programs capitalizes the ...

  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    1

    need help with my c program

    i need to make my program here do a palindrome with a word. heres my code. this programs capitalizes the first letter in each word , but i want it to do a palindrome on the final answer. please can you help me.
    Code:
    #include<stdio.h>
    #include<ctype.h>
    /*program begins here*/
    int main()
    {
    	/**/
        char string[100];
        char *ptr = string;
     /*shws the user what to do*/
        printf("Enter string and use a space after a fullstop\n");
    /*gets the string that was entered*/
        gets(string);
     
    /* looks at the first letter of string */
        *ptr = toupper(*ptr);
    	
    	/* going through the string entered*/
        while(*ptr)
        {
            if( isspace(*ptr) )
            {
                *(++ptr) = toupper(*ptr);
    			
            }
            ++ptr;
        }
    /*shows user the new string*/
        printf("your new string is %s\n",string);

  2. #2
    abyss - deep C
    Join Date
    Oct 2007
    Posts
    46
    well, i thought palindrome is something which reads the same backwards, something like
    Code:
    "madam",
    "civic",
    "level",
    "was it a rat i saw"
    search through this forum with the keyword "palindrome" and you'll see a number of threads on this subject

    maverix

  3. #3
    Nub SWE
    Join Date
    Mar 2008
    Location
    Dallas, TX
    Posts
    133
    Here's your code which compiles and spits back the same string as was entered, with capitalizing the first letter.
    It's also indented properly.

    Code:
    #include<stdio.h>
    #include<ctype.h>
    
    int main()
    {
    	char string[100];
    	char *ptr = string;
    	
    	/** Prompt the user for a string.*/
    	printf("Enter string and use a space after a fullstop: ");
    	fflush(stdout);
    	/*gets the string that was entered*/
    	gets(ptr);
    
    	/* looks at the first letter of string */
    	*ptr = toupper(*ptr);
    
    	/* going through the string entered*/
    	while(*ptr)
    	{
    		if( isspace(*ptr) )
    		{
    			ptr++;
    			*ptr = toupper(*ptr);
    
    		}
    		++ptr;
    	}
    	/*shows user the new string*/
    	printf("your new string is &#37;s\n",string);
    	
    	return 0;
    }
    Last edited by JDGATX; 04-01-2008 at 07:51 AM.

  4. #4
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    do not gets - read FAQ, use fgets
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 12:38 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 12:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 09:39 AM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

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