Need help with strings

This is a discussion on Need help with strings within the C Programming forums, part of the General Programming Boards category; So for my class I'm writing a program where you enter in a string and it states whether or not ...

  1. #1
    Registered User
    Join Date
    Oct 2009
    Posts
    9

    Need help with strings

    So for my class I'm writing a program where you enter in a string and it states whether or not it's a palindrome or not. This what I have so far. but I keep getting errors. Any ideas on what I am doing wrong?

    Code:
    #include<stdio.h>
    #include<string.h>
    
    main()
    {
    int i, j, k, FLAG, length;
    char string[100];
    char crap[100];
    
    printf("Enter in your string \n");
    scanf("%s", string);
    
    length = strlen(string);
    
    for (i=0, i<string; i++)
    {
    	crap[i] = string[length - 1 - i];
    	
    	if (string[i] == crap[i])
    		{FLAG = 1;
    		
    		else
    		{
    			FLAG = 0;
    			break;
    			}
    		}
    		
    		if (FLAG == 1)
    		{
    		printf("The string is a palindrome \n");
    		
    		else
    		
    		printf("The string is not a palindrome \n");
    		}
    }
    }

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    Code:
    for (i=0, i<string; i++)
    How many times do you expect for this loop to run?
    bit∙hub [bit-huhb] n. A source and destination for information.

  3. #3
    Registered User
    Join Date
    Oct 2009
    Posts
    9
    Quote Originally Posted by bithub View Post
    Code:
    for (i=0, i<string; i++)
    How many times do you expect for this loop to run?
    I expect it to run for the size of the string, right?

  4. #4
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    Quote Originally Posted by Skeeter View Post
    I expect it to run for the size of the string, right?
    In that case, shouldn't the code be:
    Code:
    for (i=0, i<length; i++)
    bit∙hub [bit-huhb] n. A source and destination for information.

  5. #5
    Registered User
    Join Date
    Oct 2009
    Posts
    9
    Quote Originally Posted by bithub View Post
    In that case, shouldn't the code be:
    Code:
    for (i=0, i<length; i++)
    Oh! nice catch. Thanks. I'm still getting some sort of error though, but at least we got that fixed.

  6. #6
    Registered User
    Join Date
    Oct 2009
    Posts
    9
    Nevermind I got it MYSTERY SOLVED

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Strings Program
    By limergal in forum C++ Programming
    Replies: 4
    Last Post: 12-02-2006, 02:24 PM
  2. Problem with Strings, Please help!
    By varus in forum C++ Programming
    Replies: 8
    Last Post: 11-27-2006, 10:47 PM
  3. Programming using strings
    By jlu0418 in forum C++ Programming
    Replies: 5
    Last Post: 11-26-2006, 07:07 PM
  4. Reading strings input by the user...
    By Cmuppet in forum C Programming
    Replies: 13
    Last Post: 07-21-2004, 06:37 AM
  5. menus and strings
    By garycastillo in forum C Programming
    Replies: 3
    Last Post: 04-29-2002, 11:23 AM

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