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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:16:53+00:00 2026-05-31T19:16:53+00:00

I’m trying to compare a string stored in a structure. I’m using scanf to

  • 0

I’m trying to compare a string stored in a structure. I’m using scanf to input a string and I need to search for the string in the structure. Here is the code I have:

int printing_airports(int all_routes_size,int all_airports_size){

  int i,position;
  char airport;
  printf("Enter airport code:  ");
  scanf("%s", airport);

  for(i=0;i<all_airports_size;i++){
    if(strcmp(airport,all_airports_divid[i].code) == 0){
      position = i;
    }
  }
  printf("%s",all_airports_divid[position].code);
}

This is how I declared my structures

struct all_routes{
  int id;
  char departure_code[4];
  char arrival_code[4];
};
struct all_routes all_routes_divid[500];

This is the error I’m getting when I tried to compile

y:~/enee150/project2: compile
functions.c: In function 'printing_airports':
functions.c:370:15: error: invalid type argument of unary '*' (have 'int')
functions.c:373:5: warning: passing argument 1 of 'strcmp' makes pointer from integer without a cast [enabled by default]
/usr/include/iso/string_iso.h:64:12: note: expected 'const char *' but argument is of type 'char'

What am I doing wrong? Please help me.

  • 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-05-31T19:16:54+00:00Added an answer on May 31, 2026 at 7:16 pm

    You declare airport as a char

    char airport;
    

    but use it as a string. Declare it char airport[100]; or so.

    printf("Enter airport code:  ");
    scanf("%s", airport);
    

    scanf requires a pointer to the variable the result shall be stored in as argument. When declared as char, airport is passed as an int to scanf, that is why the first message mentions int. The argument is dereferenced (unary *) to find the location where to store the scan result.

    for(i=0;i<all_airports_size;i++){
      if(strcmp(airport,all_airports_divid[i].code) == 0){
    

    strcmp requires a pointer (to a 0-terminated string) as argument. If passed an integral type like char, without explicit cast, the compiler warns about that (because 99.99+% of the time it’s wrong to do that).

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have thousands of HTML files to process using Groovy/Java and I need to
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I need to clean up various Word 'smart' characters in user input, including but
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I am trying to loop through a bunch of documents I have to put
I have a bunch of posts stored in text files formatted in yaml/textile (from
I need to write an AS3 program to search for a certain keyword in

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.