Thread: Urgent help in finding the length

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    17

    Urgent help in finding the length

    Hello all,

    I need help with finding the length of the string input by the user.

    It prints out 100 each time.

    Also i cannot use the strlen function

    Also is there a way that each of those strings can be converted to single characters? like each of s can be assigned to a char?

    Thank You for ur help...

    Code:
    #include <stdio.h>
    
    #define MAX 100
    
    int main( int argc, char *argv[]) {
        char s[MAX];
        int i, j=0;
    //    char c;
    
        printf("Enter a string\n");
        fgets(s, MAX, stdin);
    
        for(i =0; i<MAX; i++ ) {
           s[MAX] = j;
           j++;
        }
    
        printf("The repetition of this line is:");
        puts(s);
    
        printf("The length is %d.\n", j);
        return 0;
    
    }
    Last edited by s.sidak; 10-31-2010 at 08:55 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. char Handling, probably typical newbie stuff
    By Neolyth in forum C Programming
    Replies: 16
    Last Post: 06-21-2009, 04:05 AM
  2. Strange string behavior
    By jcafaro10 in forum C Programming
    Replies: 2
    Last Post: 04-07-2009, 07:38 PM
  3. Finding length of char **
    By Zarniwoop in forum C Programming
    Replies: 12
    Last Post: 04-24-2008, 06:48 AM
  4. Need help with a snake game (ncurses)
    By Adam4444 in forum C Programming
    Replies: 11
    Last Post: 01-17-2007, 03:41 PM
  5. Finding maximum queue length
    By crepincdotcom in forum Networking/Device Communication
    Replies: 2
    Last Post: 08-05-2004, 09:31 AM