#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    2
    Rep Power
    0

    Search a requested string and output into 16 byte


    So basically here I have a menu in my C program and if I were to select option 2, I would enter a string up to 30 characters and it would output each block of 16 bytes should be shown which contains a character in the requested string. However, when I compile and run the program and search for the string, nothing happens. Can anyone please tell me what I may be doing wrong? Thanks

    Code:
    else if (select == 2){
        printf("Enter a string of up to 30 characters: ");
        scanf("%s", &userstr);
               
              //Compares both user's string and file string
           for (i = 0; i < size; i++){ 
              if (strcmp (buffer, userstr) !=0){
                 printf("String match");              
             }
                 else {
                   printf("No string match");
                 }
         }
      }
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Location
    India
    Posts
    95
    Rep Power
    4
    strcpm return 0 if both string are same and non zero if both are not same.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    2
    Rep Power
    0
    Ok. So should I replace the "strcpm" with "strcmp"? If so, I tried that and the program came up with an error.
  6. #4
  7. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,145
    Rep Power
    2222
    That had been a typographical error. The function name is strcmp as you originally had it. The point that you didn't understand what its return value means is still valid. From the documentation (eg, man page strcmp at http://linux.die.net/man/3/strcmp):
    Return Value
    The strcmp() and strncmp() functions return an integer less than, equal to, or greater than zero if s1 (or the first n bytes thereof) is found, respectively, to be less than, to match, or be greater than s2.
    The syntax and operation of the standard library functions are well-documented and freely available to all. In UNIX, this documentation -- "the frakking manual" that RTFM tells you to read -- is available on the computer through the man pages. These man pages have also been posted in a multitude of places on the Web; through Google, there are about 60,300 instances of man pages for strcmp.

    So why didn't you read the frakking manual?
    Last edited by dwise1_aol; March 21st, 2013 at 10:43 AM.

IMN logo majestic logo threadwatch logo seochat tools logo