Thread: having some problems...

  1. #1
    Registered User Vber's Avatar
    Join Date
    Nov 2002
    Posts
    807

    having some problems...

    I have the following code:
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    #define SIZE (sizeof(strings)/4)
    int main(void)
    {
        int i;
        char *strings[] = {
            "Line1 here",
            "Line2 there",
            "Line3 whatever",
            "Line4 blahhh",
        };
        
        for (i=0; i<SIZE; ++i)
            strings[i] = strrev(strings[i]);
        
        for (i=0; i<SIZE; ++i)
            printf("%s\n",strings[i]);
        
        system("PAUSE");
        return 0;
    }
    I'm having problems with it, when I run it it freezes, but it compiles well, I think I'm not using pointers well.

    Thanks in advance.

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >> char *strings[]
    This is an array of pointers to strings. You are initialising it to pointer to a few string literals. String literals cannot safely be modified.

    Try this:
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    #define SIZE (sizeof(mystrings)/sizeof(mystrings[0]))
    
    int main(void)
    {
        int i;
        char mystrings[][100] = {
            "Line1 here",
            "Line2 there",
            "Line3 whatever",
            "Line4 blahhh",
        };
        
        for (i=0; i<SIZE; ++i)
            strrev(mystrings[i]);
        
        for (i=0; i<SIZE; ++i)
            printf("%s\n",mystrings[i]);
        
        system("PAUSE");
        return 0;
    }
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Registered User Vber's Avatar
    Join Date
    Nov 2002
    Posts
    807
    Thanks Hammer.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 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
  2. C Pointers Problems
    By mhelal in forum C Programming
    Replies: 8
    Last Post: 01-10-2007, 06:35 AM
  3. String Manipulation problems -_-
    By Astra in forum C Programming
    Replies: 5
    Last Post: 12-13-2006, 05:48 PM
  4. Rendering problems (DirectX?)
    By OnionKnight in forum Tech Board
    Replies: 0
    Last Post: 08-17-2006, 12:17 PM
  5. contest problems on my site
    By DavidP in forum Contests Board
    Replies: 4
    Last Post: 01-10-2004, 09:19 PM