In my function I need to use scanf to read a title of an album from the user and go through a list of albums to see if the title matches any in my list.
The instructions say "please use "%[^\n]" in scanf to accept blanks in the string" and I don't know how to use that in scanf.
Also it says to use *strstr to compare the title entered by the user and the title of the album in the database. Im not sure how to use that either, can anyone explain??
Question about Applied C and strings?
Allright, the scanf statement is where we start. The '[^\n]' is a list specifier that says to the function "take everything but a newline as valid and store it". In this instance your call will look something like this:
scanf("%[^\n]s", %26amp;SomeVariableArray);
The function strstr and information on other standard ANSI C and C++ things can be found at the second URL below. The first is a direct link to information on the strstr function. Good luck!
Reply:OOPS! In my haste I should have typed:
scanf("%[^\n]s", %26amp;SomeVariableArray[0]);
which would make the address operator return a pointer value set to the array's first element into the scanf function as expected. It is best to do these things yourself, IMHO. Griz803 Report It
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment