Thread: [STRING][to count][characters]

  1. #1
    Registered User
    Join Date
    Dec 2002
    Posts
    44

    Unhappy [STRING][to count][characters]

    How I make to determine the length of one string?


    example
    String[ ] = 'Ciao mamma come stai ' ;

    this tightens is composed from 21 characters. how I make to realize a program that counts me the length of strings ?
    http://linuxdesktop.it

  2. #2
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    int main(void)
    {
       char msg[] = "Ciao mamma come stai ";
       printf("Length of \"%s\" is %d\n", msg, strlen(msg));
       return 0;
    }

  3. #3
    Registered User Azuth's Avatar
    Join Date
    Feb 2002
    Posts
    236
    Do you need to write your own function (ie, is it homework/assignment) or do you just want to know how to get the length of a string? If it's the latter, the code below should help you along, if it's the former, well you need to have a go and post some code, then we'll help make it work.

    strlen is in the header string.h

    Code:
    #include <stdio.h>
    #include <string.h>
    
    int main(void)
    {
       char *string = "'Ciao mamma come stai";
    
       printf("%d\n", strlen(string));
       return 0;
    }
    Demonographic rhinology is not the only possible outcome, but why take the chance

Popular pages Recent additions subscribe to a feed