You have to make four changes:

  1. Change

    char * str[25];
    

    to

    char str[25];
    

    as you want an array of 25 chars, not an array of 25 pointers to char.

  2. Change

    char car;
    

    to

    int car;
    

    as getchar() returns an int, not a char.

  3. Change

    scanf("%[^\n]s", &str);
    

    to

    scanf( "%24[^\n]", str);
    

    which tells scanf to

    1. Ignore all whitespace characters, if any.
    2. Scan a maximum of 24 characters (+1 for the Nul-terminator '\0') or until a \n and store it in str.
  4. Change

    printf("\nThe sentence is %s, and the character is %s\n", str, car);
    

    to

    printf("\nThe sentence is %s, and the character is %c\n", str, car);
    

    as the correct format specifier for a char is %c, not %s.

Answer from Spikatrix on Stack Overflow
🌐
Programiz
programiz.com β€Ί c-programming β€Ί c-strings
Strings in C (With Examples)
Thus, the name in scanf() already points to the address of the first element in the string, which is why we don't need to use &. You can use the fgets() function to read a line of string.
🌐
GeeksforGeeks
geeksforgeeks.org β€Ί c language β€Ί strings-in-c
Strings in C - GeeksforGeeks
November 14, 2025 - The simplest way to read a string in C is by using the scanf() function.
🌐
Reddit
reddit.com β€Ί r/c_programming β€Ί how to scan strings?
r/C_Programming on Reddit: How to Scan Strings?
July 15, 2020 -

I am trying to develop a code that would delay the printing of letters onto the console so that it looks like its being typed rather than displaying it all at once. To do that I'm trying to scan the number of characters in a string until it reaches a newline character. Then activating the sleep function while it types every letter in a for loop that reads every character and displays it. But I'm having trouble trying to figure out how to scan the letters, any suggestions on how I could accomplish this?

🌐
Sololearn
sololearn.com β€Ί en β€Ί Discuss β€Ί 1746871 β€Ί how-to-input-a-string-using-scanf-in-c-
How to input a string using scanf() in C ? | Sololearn: Learn to code for FREE!
1- Declare your string variable. 2- In scanf(), use %s as your format specifier. 3- When assigning the format specifier to a variable, don't use '&' (according to my experience, adding & never worked.)
🌐
Educative
educative.io β€Ί answers β€Ί how-to-read-data-using-scanf-in-c
How to read data using scanf() in C
In C, the scanf() function is used to read formatted data from the console. ... Format specifier is a special character which is used to specify the data type of the value being read.
🌐
Reddit
reddit.com β€Ί r/c_programming β€Ί can someone please tell me how to declare a string in c and read them with scanf()? tutorials point/geekforgeeks/other internet resources are total garbage and hard to follow for beginners.
r/C_Programming on Reddit: Can someone please tell me how to declare a string in C and read them with scanf()? Tutorials point/geekforgeeks/other internet resources are total garbage and hard to follow for beginners.
April 18, 2021 -

Hi,

So tutorialspoint, geeksforgeek, javatpoint, those websites that claim to have C/C++ tutorials are a bunch of shitty Indian garbage tutorials that are not suited for beginners at all. I'm trying to learn how to declare a string variable with C and read input with scanf() and I get a bunch of different information from all three sites and I'm really frustrated and confused. Do you do?

#include <stdio.h>  
int main(void)
{
    char name[100000000];
    printf("What's your name?\n");
    scanf("%c", char);
}

Or is it

#inclue <stdio.h>

int main(void)
{
    char** x;
    printf("What's your name?\n");
    scanf("%c", x)
}

Or is it

#include <stdio.h>

int main(void)
{
    string x;
    printf("What's your name?\n");
    scacnf("%s", x);
}

Or is it

#include <stdio.h>

int main(void)
{
    char **name;
    printf("What's your name?\n");
    scanf("%c", name)

What the fuck is it? Is it %c or %s for the format code, and it is char name[] or char **var_name or **char var_name?? Someone please tell me. All these online tutorials are fucking GARBAGE and I can't find a clear answer anywehere

Top answer
1 of 3
3
K&R is not intended to be a complete manual for every function in the C library: that's what man pages are for. K&R is a tutorial that introduces the C language (that is, the things that compilers deal with -- keywords, data types, syntax, ...), and shows some ways they can be connected together to make working programs. There are countless libraries that C can call: X-windows graphic libraries, and encryption libraries, and database access libraries, and networking libraries. They all come with their own manual pages. If the C Language book covered all those, then (a) you would not be able to lift it, and (b) it would be permanently out of date, as things evolve. My K&R is a First Edition from 1978, so the page numbering is not going to be the same as yours -- I'm not sure the section numbering will even be the same. That's why you use your own volume's index. Section 7.4 "Formatted Input" in mine covers scanf, 7.5 for sscanf, and 7.6 for fscanf. They are very similar, and use the same format "conversion specification" options: scanf reads from stdin, fscanf reads from a file, and sscanf reads from a string in memory. They work best for input where you are not too fussed about how it fits into input lines, so they are quite sloppy about whitespace. getline appears in section 1.9, as an example of how to write a function in C, and again in section 4.1 which is about how to structure a larger program. At the time, there was no standard library function getline(). When this was added into a library later, it was made to do the same kind of thing, but allows for expanding the input length automatically. So getline() reads a whole line from a file (which can be stdin or any other file or device), but it does not unpack any fields or values itself: there are a whole family of other functions that deal with those things. Some of those functions have names like strtok, strtol, strtod, and they all have man pages. Usually, there is a "See Also" section that links you into similar or related functions. fgets() is in section 7.8 "Line Input and Output" along with fputs(). fgets() is like getline, but simpler: you provide space for the string, but if it is too short you don't get a whole line of data, and you have to deal with that problem yourself. gets() is like fgets() but for stdin only. Also, it does not care at all about the space you provided for the input, and so can be misused to corrupt your program. The first four words in the man page are "Never use this function". All the code sections you posted are wrong, and here's why. char name[100000000]; reserves a buffer of 100 million characters as a local (on-stack) variable. That will use up all your stack and more besides, and your program won't run (probably not even load). char *x; would create a pointer to some chars, but it is not initialised to point to anywhere -- it is a pointer to something that does not exist. char **x; is even worse: is is a pointer to a pointer that does not exist, that would point to some chars that don't exist either. string x; uses a type "string" that does not exist in C. Some CS50 courses provide a header file that fixes up stuff like "string" to make your code easier to write, but they are not proper C and they hide the actual details, which is a piss-poor way to learn. scanf ("%c") reads exactly one character from the input. That is not a string. scanf ("%s") reads a string (like a name) from the input. It reads a real word: it skips any preceding whitespace, and it then only fetches text up to the next whitespace. Also, second example says #inclue and misses a ; off the scanf line, third one says scacnf, fourth one misses ; off scanf and a closing } . Compilers don't allow for carelessness. "string" is not part of the C language. It is verbal shorthand for "A row of text characters that ends with a zero (ASCII NUL) character. A row of things in C is usually called an array. To read and show a name in C, this would be good: #include int main(void) { char name [84]; //.. Allowing space for NUL terminator. printf("What's your name?\n"); scanf("%80s", name); //.. Limit field width on read. printf ("Good to meet you, %s!\n", name); } OK, I've spent 75 minutes writing this up. You need to do some work now. K&R is quite readable -- worth skimming the whole thing just to get an idea of what is in there -- get the shape of the language and fill in the detail later. Those dumb tutorials you found are mainly written for vanity by people who don't understand C themselves. 80% of it is junk. It really is worth reading enough man pages to understand why the information is presented like they do.
2 of 3
3
You should DM u/JacksonSteel -- you are brothers under the skin.
Find elsewhere
🌐
Cprogramming
cboard.cprogramming.com β€Ί c-programming β€Ί 175738-how-scan-string-user.html
How to scan string from user
#include<stdio.h> int main (void) { unsigned int grade; printf("Promot user to enter grade of student : "); scanf("%d",&grade); if(grade > 100) { printf ("Entered invalid grade"); } else if (grade > 35) { printf ("Your grade is %d \n You are passed",grade); } else { printf ("Your grade is %d \n You are failed",grade); } return 0; } Promot user to enter grade of student : 101 Entered invalid grade Your grade is 45 You are passed Your grade is 34 You are failed if you compare first and second, both are similar the difference is only in scanning type. In first example, I was trying to scan name while in second example I was trying to scan numbers. When I scan numbers I don't need to use enum or define but when I need to scan string or name why I need to use enum or something like define red
🌐
Quora
quora.com β€Ί How-do-you-read-a-string-into-an-array-using-scanf-in-the-C-programming-language
How to read a string into an array using scanf in the C programming language - Quora
Answer (1 of 3): You can do something like this: [code]char buf[16]; scanf("%s", buf); [/code]But this will trample the stack if you enter more than 15 characters. For example: [code]#include int main(int argc, char **argv) { char buf[16]; int ...
🌐
GeeksforGeeks
geeksforgeeks.org β€Ί c language β€Ί scanf-in-c
scanf in C - GeeksforGeeks
Also, we don't need to use the &operator for the address of name. In C, scanf() provides a feature called scanset characters using %[] that lets you read a sequence of characters until a certain condition.
Published Β  October 13, 2025
🌐
IncludeHelp
includehelp.com β€Ί c β€Ί c-program-to-read-string-with-spaces-using-scanf-function.aspx
C program to read string with spaces using scanf() function
We have to read a character from ... then we should read a temporary character which may available in the input buffer) I am using a statement scanf("%c",&temp); before reading the string (which is going to be read after an integer input)....
🌐
OpenGenus
iq.opengenus.org β€Ί how-to-take-string-input-in-c
How to take string input in C?
September 7, 2021 - The input function scanf can be used with %s format specification to read in a string of characters.
🌐
GeeksforGeeks
geeksforgeeks.org β€Ί c language β€Ί taking-string-input-space-c-3-different-methods
Taking String input with space in C (4 Different Methods) - GeeksforGeeks
July 23, 2025 - We can take string input in C using scanf("%s", str). But, it accepts string only until it finds the first space. There are 4 methods by which the C program accepts a string with space in the form of user input.
🌐
Scaler
scaler.com β€Ί home β€Ί topics β€Ί strings input and output functions in c
Strings Input and Output functions in C
November 16, 2023 - The scanf() function is probably the easiest way to string input in C. We just need the access specifier %s and the pointer to the variable where we want the string to be stored, and it becomes very easy to input the string in C.
🌐
Quora
quora.com β€Ί How-do-I-scan-a-string-with-spaces-but-ignore-them-while-reading-in-C-programming
How to scan a string with spaces but ignore them while reading in C programming - Quora
Answer (1 of 4): A2A You can scan a string using [code ]%[^\n][/code] in C. It will scan blankspaces as well. While processing the string you can check for every character. If the present character is blankspace you can simply ignore the character.
🌐
Sternum IoT
sternumiot.com β€Ί home β€Ί scanf c function – syntax, examples, and security best practices
scanf C Function – Syntax, Examples, and Security Best Practices | Sternum IoT
January 31, 2024 - However, the scanf() function stops reading a string when it encounters a white space. To read a full line of text, including white spaces, you can use the fgets() function instead.
🌐
Quora
quora.com β€Ί How-can-I-scan-for-a-word-in-C-E-g-Scan-red-and-then-compare-it-to-a-string
How to scan for a word in C? E.g. Scan 'red' and then compare it to a string - Quora
Answer (1 of 4): There are multiple ways of doing this operation. One way can be: * You can define pointer char * Allocate dynamic space * Keep track of last index * Compare it's elements one by one such as arrays