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 8986753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:37:33+00:00 2026-06-15T21:37:33+00:00

Normally strcmp is used with two arguments [e.g. strcmp(str1,garden)], and it will return 0

  • 0

Normally strcmp is used with two arguments [e.g. strcmp(str1,”garden”)], and it will return 0 if both are the same.

Is it possible to compare part of the input, say the first five character of the input? (for example, strcmp(str1,"garde",5))

#include <stdio.h>
#include<string.h>

int main(void) {

    char str1[] = "garden";

    if (strcmp(str1, "garden") == 0)
    {
        printf("1");
    }
    if (strcmp(str1, "garden", 6) == 0)
    {
        printf("2");
    }
    if (strcmp(str1, "garde", 5) == 0)
    {
        printf("3");
    }
    return 0;
}
  • 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-15T21:37:34+00:00Added an answer on June 15, 2026 at 9:37 pm

    Use strncmp:

    if (strncmp(str, "test", 4) == 0) { printf("it matches!"); }
    

    See http://www.cplusplus.com/reference/cstring/strncmp/ for more info.

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

Sidebar

Related Questions

Normally, a qualified component will be injected to annotated fields with the same qualifier:
normally when I'm using a viewcontroller that will push the current viewcontroller out of
Normally I do this for all my user inputs both strings and numerical inputs:
Normally LIKE statement is used to check the pattern like data. example: select *
Normally, I'd choose List<String> [or, in VB, List(Of String) ] over StringCollection whenever possible:
Normally boot strap loaders are written using assembly languages. Is it possible to dot
Normally IN is used with one value: SELECT * FROM data WHERE f1 IN
Normally a widget is used by calling CController::widget() on an instance of CController ,
Normally if you have showuserlocation enabled, and going to mapview, there will blue point
Normally whenever I've needed to lock a row in a database, I've used a

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.