I have learned a few programming languages and am now in the beginning stages of teaching myself C with "C Programming, Second Edition for the absolute beginner".
I'm enjoying the book but have run into some difficulties in the second chapter exercies. The exercise states as follows:
Create a program that prompts a user for her name. Store the user's name using the scanf() function and return a greeting back to the user using her name.
Simple enough in another language where I could just declare a string and prompt the user to enter said string. This is the second chapter of the book and strings are not covered until chapter 8. Through online research and this forum I have created this solution:
// Ex. 2.3, Name
// This program prompts the user to enter their name and then displays a greeting to
// the user utilizing the name entered.
#include <stdio.h>
int main()
{ // begin main()
char dump, stringName[40];
printf("Please enter your name: ");
scanf("%[^\n]", stringName);
scanf("%c", &dump);
printf("\nHello %s\n", stringName);
return 0;
} // end main()
It works though I don't understand the "dump" aspect or the [^\n] from above. The main question I have is how was I supposed to create a solution to this problem without using something that hasn't been taught yet and won't be for numerous chapters.