Results 1 to 4 of 4

Thread: What am I doing wrong? Please help

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Unhappy What am I doing wrong? Please help

    Heres the problem i have: Write a program that reads in a line of input and then prints the line out in reverse order. Recall that you can use scanf() with the %c specifier to read one character at a time from input and that the newline character (\n) is generated when you press the Enter key.

    this is the code i have but it doesnt work. what am i doin wrong. Any help would be greatly appreciated.

    Code:
    #include <stdio.h>
    #include <string.h>
    int main(void)
    {
         char ch[255];
         int index, n, i;
    
         for (index = 0; ch[index] != '\n'; index++)
         {
                scanf("%c", &ch[index]);
    
         }
    
         n = strlen(ch);
    
         for (i = n - 1; i >= 0; i--)
         {
                printf("%c", ch[i]);
         }
    
         system ("pause");
    
         return 0;
    }


    Last edited by fallenangel1331; 06-25-2008 at 11:06 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact