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

  • Home
  • SEARCH
  • 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 6377431
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:52:20+00:00 2026-05-25T01:52:20+00:00

My code #include <stdio.h> #include <stdlib.h> #include <ctype.h> void getData(short int *number, char *string)

  • 0

My code

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

void getData(short int *number, char *string)
{
    printf("\nPlease enter a number greater than zero: ");
    scanf("%hd", number);

    printf("Please enter a character string: ");
    scanf("%s", string);
}

void echoPair(short int *number, char *string)
{
    printf("Number: %hd Character(s): %s\n", *number, string); 
}

int main()
{
    short int *number = 0;
    char string[32] = {0};

    printf("This program will ask you to enter a number greater than zero and \na character string with less than 32 characters \ninput.");

    getData(&number, &string);
    echoPair(&number, &string);
    return(0);
}

The code works fine, but I receive these compiler warnings

warning: passing argument 1 of ‘getData’ from incompatible pointer type
warning: passing argument 2 of ‘getData’ from incompatible pointer type
warning: passing argument 1 of ‘echoPair’ from incompatible pointer type
warning: passing argument 2 of ‘echoPair’ from incompatible pointer type

If do this

    getData(number, string);
    echoPair(number, string);

The warnings go away, but the program gets a “Segmentation fault: 11” after I enter the first number in the getData function.

Anyone know how to remove the warnings and keep the program working?

Thanks

  • 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-25T01:52:21+00:00Added an answer on May 25, 2026 at 1:52 am

    There are a number of problems here.


    First, the line:

    short int *number = 0;
    

    should be:

    short int number = 0;
    

    Because you used the former, it gave you a null pointer to a short. That’s not what you want since the first dereference of that beast will probably crash your code (or, worse, not crash your code but cause strange behaviour).


    Secondly, you don’t need to pass in the address of strings, they automatically decay to an address, so change:

    getData (&number, &string);
    echoPair (&number, &string);
    

    to:

    getData (&number, string);
    echoPair (&number, string); // but see last point below.
    

    And, last of all, you don’t need to pass in the address just to print it, you can just pass in the value, hence:

    echoPair (&number, &string);
    

    becomes:

    echoPair (number, string);
    

    As a whole, I think what you want is:

    #include <stdio.h>
    #include <stdlib.h>
    #include <ctype.h>
    
    void getData(short int *number, char *string) {
        printf("\nPlease enter a number greater than zero: ");
        scanf("%hd", number);
    
        printf("Please enter a character string: ");
        scanf("%s", string);
    }
    
    void echoPair(short int number, char *string) {
        printf("Number: %hd Character(s): %s\n", number, string);
    }
    
    int main (void) {
        short int number = 0;
        char string[32] = {0};
    
        printf("Blah blah ...");
    
        getData(&number, string);
        echoPair(number, string);
        return(0);
    }
    

    As an aside, you don’t ever want to see unbounded string scans like:

    scanf ("%s", string);
    

    in production-ready code. It’s a buffer overflow vulnerability waiting to happen, since you don’t control what the user will input. In your particular case, the user entering more than (about) 30 characters may cause all sorts of weird behaviour.

    The scanf function is for scanning formatted text, and there’s not many things more unformatted than user input 🙂

    If you want a robust user input function, see here.

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

Sidebar

Related Questions

This is the code: #include <stdio.h> #include <stdlib.h> void acceptMaze(char maze[ROW][COLOUMN], int nrows, int
Please see this piece of code: #include<stdio.h> #include<string.h> #include<stdlib.h> int main() { int i
consider the code #include<stdio.h> int main(void) { char* a; scanf(%s,a);//&a and &a[0] give same
This code #include <stdio.h> #include <stdlib.h> #include <time.h> int main () { printf (First
i have following code #include <stdlib.h> #include <stdio.h> int sorter( const void *first_arg,const void*
I have the following code: #include <stdio.h> #include <stdlib.h> #include <string.h> #include <curl/curl.h> char
The code: #include <stdio.h> #include <stdlib.h> int main() { char * cp = malloc(sizeof
Here is my code: #include <stdio.h> #include <stdlib.h> int main(){ int n=10; char *s=
Test the following code: #include <stdio.h> #include <stdlib.h> main() { const char *yytext=0; const
My C code #include <stdio.h> #include <stdlib.h> #include help.h int test(int x, P *ut)

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.