Explore BrainMass

Explore BrainMass

    Writing Strings and Integers in C Programs

    Not what you're looking for? Search our solutions OR ask your own Custom question.

    This content was COPIED from BrainMass.com - View the original, and get the already-completed solution here!

    I am trying to write a C program that accepts a string and two integer numbers from a user. Each of these inputs should be preceded by a prompt and stored using individual variable names.

    Then I am trying to have the program call a function that assembles the input data into a single string, then display the assembled string using the puts() call command. Please help me with these tasks.

    © BrainMass Inc. brainmass.com September 27, 2022, 5:47 pm ad1c9bdddf
    https://brainmass.com/computer-science/c/writing-strings-integers-c-programs-436209

    SOLUTION This solution is FREE courtesy of BrainMass!

    Hi,

    You may do something like this...

    ----------------

    //use angular brackets instead of " " for stdio.h.
    #include "stdio.h"

    //function to display the output string using puts
    display(char str[], int x, int y)
    {
    str = str + x + y;
    puts(str);
    }

    //main function
    int main()
    {

    char aString[50];
    int a, b;

    printf ( "Enter the stringn" ) ;
    gets ( aString ) ;

    printf ( "Enter 1st integern" ) ;
    scanf("%d",&a);

    printf ( "Enter 2nd stringn" ) ;
    scanf("%d",&b);

    display(aString, a, b);

    return 0;
    }

    -----------------

    Hope this helps!

    This content was COPIED from BrainMass.com - View the original, and get the already-completed solution here!

    © BrainMass Inc. brainmass.com September 27, 2022, 5:47 pm ad1c9bdddf>
    https://brainmass.com/computer-science/c/writing-strings-integers-c-programs-436209

    ADVERTISEMENT