Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8834083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:55:57+00:00 2026-06-14T08:55:57+00:00

This is my code: if(strcmp(pch,map[i].name)==0){ printf(Equal\n); return 0; } pch is read from a

  • 0

This is my code:

        if(strcmp(pch,map[i].name)==0){
            printf("Equal\n");
            return 0;
        }

pch is read from a file, map[i].name has a known size of 64.
This works great for strings smaller than 64. when comparing these two strings below of size 63:

file11111111111111111111111111111111111111111111111111111111111 and

file11111111111111111111111111111111111111111111111111111111111

everything is peachy and the result as expected is equal, but when these two (of size 64) are compared:

file111111111111111111111111111111111111111111111111111111111111 and

file111111111111111111111111111111111111111111111111111111111111

the return is false.
I thought of doing:

        if(strncmp(pch,map[i].name,64)==0){
            printf("Equal\n");
            return 0;
        }

And it does work for strings of exact size of 64, but for strings that
are smaller the result is random.
What kind of quirkiness am i dealing with here?

EDIT: this is the full code:

    char * pch;
    char tempFilesNeeded[100*64+100];
    strcpy(tempFilesNeeded,map[i].filesNeeded);
    pch = strtok(tempFilesNeeded,",");
    while (pch != NULL)
    {
        if(strcmp(pch,map[i].name)==0){
            printf("Equal\n");
            return 0;
        }

        pch = strtok (NULL, ",");
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T08:55:58+00:00Added an answer on June 14, 2026 at 8:55 am

    Well, if it’s

    char pch[64];
    

    then you can’t have 64 visible characters in there, since the last entry is needed for the termination. If you do have "file111111111111111111111111111111111111111111111111111111111111" in that array, it’s not terminated and calling strcmp() on it invokes undefined behavior.

    Also, as a minor point, saying that strcmp() returns “false” is wrong, since its return is not boolean. It returns the relation between the two first differing characters; if no characters differ the strings are equal, then it returns zero.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This code comes from: http://code.activestate.com/recipes/577090-file-encryption-using-stream-cipher/ import sys import random if len(sys.argv) != 4: print
So, I have this piece of code, which will just read the message from
DISCLOSURE: This is homework. The code below is meant to read a command file
Basically this is a program which I take a text file with some code
This program so far has one purpose, take in two integers(the size of the
I have this code below which checks whether the user has entered a syntactically
I am getting a linker error building this code: Exclude.h file class IsExclude {
This part of code is used by a client when receiving a file: void
I am having this code in which I am getting BAD FILE DESCRIPTOR problem
I have the following code (from a previous question on this site) which retrieves

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.