Thread: Size_t problem

  1. #1
    Registered User
    Join Date
    Feb 2020
    Posts
    1

    Size_t problem

    I am trying to define int strcmp (char s1[], char s2[]), but i get this error:

    int main(chars1[],chars2[]) {
    int l1, l2;
    printf ("Introduza duas strings %s%s\n", s1, s2);
    l1 = size_t strlen(const char *s1);
    l2 = size_t strlen(const char *s2);
    if (l1 == l2) puts ("0");
    else if (l1 < l2) puts ("<0");
    else puts (">0");
    }



    50questoes.c: In function ‘main’:
    50questoes.c:218:10: error: expected expression before ‘size_t’
    l1 = size_t strlen(const char *s1);
    ^~~~~~
    50questoes.c:219:10: error: expected expression before ‘size_t’
    l2 = size_t strlen(const char *s2);

  2. #2
    Registered User
    Join Date
    Dec 2017
    Posts
    864
    It's hard to understand what you are trying to do, but maybe:
    Code:
    #include <stdio.h>
    #include <string.h>
     
    int main() {
        char s1[100], s2[100];
        printf ("Introduza duas strings: ");
        scanf("%99s %99s", s1, s2);
        size_t l1 = strlen(s1);
        size_t l2 = strlen(s2);
        if (l1 == l2) puts ("0");
        else if (l1 < l2) puts ("<0");
        else puts (">0");
        return 0;
    }
    The world hangs on a thin thread, and that is the psyche of man. - Carl Jung

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. what is size_t and why should we use it
    By cooper1200 in forum C Programming
    Replies: 11
    Last Post: 06-03-2019, 09:40 AM
  2. When to use size_t?
    By MutantJohn in forum C Programming
    Replies: 13
    Last Post: 04-07-2015, 05:15 PM
  3. when to use size_t ?
    By broli86 in forum C Programming
    Replies: 3
    Last Post: 06-27-2008, 10:13 AM
  4. when to use size_t instead of an int?
    By suzakugaiden in forum C++ Programming
    Replies: 1
    Last Post: 01-14-2006, 09:01 PM
  5. size_t
    By falconetti in forum C Programming
    Replies: 2
    Last Post: 02-25-2002, 08:52 AM

Tags for this Thread