How do I combine a string and a number together into one scanf function

sscanf
scanf multiple inputs
scanf string
fscanf
scanf(%d)
scanf functions c
printf in c
how to read character array in c using scanf

My program ends everytime I input a number when I ask the user for the address, I realize this everytime I input a character it keeps going but when I enter both a string and a number it automatically ends

#include <stdio.h>

int main() 
{
    int createAccount;
    char firstName[10];
    char lastName [10];
    char address[20];
    char city[15];
    int zip;
    int existingUser;
    int customerSupport;
    int pendingStatements;
    char userName[10];
    printf("1. Create Account\n");
    printf("2. Login to existing user\n");
    printf("3. Customer support\n");
    printf("4. Check pending statements \n");
    printf("Enter: ");

    scanf("%d, %d, %d, %d", &createAccount, &existingUser, &customerSupport, &pendingStatements);

    if (createAccount == 1)
    {
        printf("Name: ");
        scanf("%s", firstName);

        printf("Last Name: ");
        scanf("%s", lastName);

        printf("Address:  ");
        scanf("%s", address);

        printf("City: ");
        scanf("%s", city);

        printf("Zip: ");
        scanf("%d", &zip);
    }
    else if (existingUser == 2)
    {
        printf("Username: ");
        scanf("%s", userName);
    }

}

Your first scanf() is trying to read 4 numbers separated by commas. But the user is only entering one menu choice at a time, not 4 different numbers. Because of this, none of the remaining scanf() calls are working.

int choice;
scanf("%d", &choice);
if (choice == 1) {
    ...
} else if (choice == 2) {
    ...
} else if (choice == 3) {
    ...
} else if (choice == 4) {
    ...
} else {
    printf("Invalid choice %d\n", choice);
}

What is the difference between %c and %s in c programming?, , when processing the tail of its argument list, will try to pull out a char * . In order to merge two strings into a single object, you may use the “+” operator. When writing code, that would look like this: str1 = “Hello” str2 = “World” str1 + str2


In scanf If you use more than one variables when you input first value it assign into first given variable.In good coding scanf use for only one variable.

Ex-:

int num1, num2;
printf("Enter numbers = ");
scanf("%d %d", &num1, &num2);

printf("%d\n", num1);
printf("%d\n", num2);

output

Enter numbers = 1
//It shows blank space it means you have to enter second number
1
2

//You can input two numbers by puting spaces among them. Then it will assign given variables
Enter number = 1 2
1
2

you can see first entered value always assign into first variable. There for we don't need multiple variables to do one work. Use only one variable is fine

There for in your case you have to use one variable for check status

#include <stdio.h>

int main() 
{

    int choose = 0;
    char firstName[10];
    char lastName [10];
    char address[20];
    char city[15];
    int zip;
    char userName[10];

    printf("1. Create Account\n");
    printf("2. Login to existing user\n");
    printf("3. Customer support\n");
    printf("4. Check pending statements \n");
    printf("Enter: ");

    scanf("%d", &choose);


    if (choose== 1)
    {
        printf("Name: ");
        scanf("%s", firstName);

        printf("Last Name: ");
        scanf("%s", lastName);

        printf("Address:  ");
        scanf("%s", address);

        printf("City: ");
        scanf("%s", city);

        printf("Zip: ");
        scanf("%d", &zip);
    }
    else if (choose== 2)
    {
        printf("Username: ");
        scanf("%s", userName);

    }
    else if (choose== 3)
    {
        printf("..........");
    }
    else if (choose== 4)
    {
        printf("..........");
    }
    else
    {
        printf("Error number\n");
    }

    return 0;

}

Reading a string with scanf, ("%d %d %d", &x[0], &x[1], &x[2]); printf("You entered %d, %d, and %d. The simplest and most common method is to use the plus symbol ( +) to add multiple strings together. Simply place a + between as many strings as you want to join together: >>>. >>> 'a' + 'b' + 'c' 'abc'. In keeping with the math theme, you can also multiply a string to repeat it: >>>. >>> 'do' * 2 'dodo'.


#include <stdio.h>

int main() 
{

//int createAccount;
char firstName[10];
char lastName [10];
//int address;
char address[20];
char city[15];
int zip;
char password[10];
int choice;



// int existingUser;
// int customerSupport;
// int pendingStatements;
char userName[10];
printf("1. Create Account\n");
printf("2. Login to existing user\n");
printf("3. Customer support\n");
printf("4. Check pending statements \n");
printf("Enter: ");
scanf("%d", &choice);

if (choice == 1)
{
    printf("Name: ");
    scanf("%s", firstName);

    printf("Last Name: ");
    scanf("%s", lastName);

    printf("Address:  ");
    scanf("%s", address);

    printf("City: ");
    scanf("%s", city);

    printf("Zip: ");
    scanf("%d", &zip);
}
else if (choice == 2)
{
    printf("Username: ");
    scanf("%s", userName);
    printf("Password: ");
    scanf("%s", password);
}


}

Multiple inputs at one line?, The preceding statement reads an integer value into the variable highscore. One of the most common ways to put the scanf() function to use is to read in a The %s conversion character directs scanf() to look for a string as input, just as %​s  2. scanf() function in C language: In C programming language, scanf() function is used to read character, string, numeric data from keyboard; Consider below example program where user enters a character. This value is assigned to the variable “ch” and then displayed.


printf and scanf, When you pass arguments to functions, you separate each one with a comma - here, the previous scanf statement by this: "Read in an integer from the input string, then go to the address of the variable called a and put the value there". C program - Read string with spaces using scanf() function, here we are writing how to read a complete string with multiple spaces using scanf() and how to print? A humble request Our website is made possible by displaying online advertisements to our visitors.


Basics of the scanf() Function in C Programming, STRING A string is a sequence of characters which is treated as a single data item. We have used strings in a number of examples in the past. (2) Combining strings together. + Reading String from Terminal The familiar input function scanf can be used with "%s" format specification to read in a string of characters. Concatenation means joining two values or two strings together, similar to excel we use & or also known as ampersand operator to concatenate, two concatenate two strings we use & operator like String 1 & String 2, now there is an important thing to remember and that is while using the & operator we need to provide spaces or VBA will consider it as long.


Output and Input in C, The various operations performed on character strings are explained below. use of the standard string inputting (scanf()) and string outputting (print/0) functions from refers to the joining of two or more strings together to form a single string. I have a cell that the user types what column a specific cell sits in, and I want to combine the letters in that cell with a specific row to get the cell id for what I want to display. I can get the letters and number together but I cant make the answer be used to describe another cell. IE. choice of A, B, C, D columns.