I'm new to C programming, but not at all new to programming in general. My professor wants me to use scanf() function to read a string of characters into a variable. I missed a day of class and did not learn how to actually go about this. From what I could get from his lecture and the students around me, I've come up with the following:
What I am trying to do is use scanf to put the input into *name. I can do that fine, but it also reads the \n and places it into *name. That is where I know I am going wrong. What I have above is one of many things I tried and failed at.Code:char *name; char *bufp; char buf[BUFL]; printf("Please enter your name: "); name = fgets(buf, BUFL, stdin); buflen = strlen(name); buf[buflen-1] = "\0";
How can I read a string using scanf() into a variable, and get rid of the \n (replace it with a NUL byte).