-I know how to scanf a character but dont know how to scanf a string.
This is correct?
scantf("%f",lop);
-How to define the variable to save the string in?
string "lop";
Thanks,
-I know how to scanf a character but dont know how to scanf a string.
This is correct?
scantf("%f",lop);
-How to define the variable to save the string in?
string "lop";
Thanks,
Read: scanf
Also read: FAQ > Get a line of text from the user/keyboard (C) - Cprogramming.com
Quzah.
Hope is the first step on the road to disappointment.
There's no such thing as a "string".
Sure, some programming languages have a typedef for it, but it doesn't truly exist. What people refer to as a string is simply an area of consecutive memory bytes. You'll see it referred to as a "char array" (an array of characters in the stack), or a "char pointer" (points to the first byte in memory that the "string" is stored in the heap). The "string" type in any language is one of those two things, and high-level (read: less powerful) languages do all of the memory management for you.
This is quite possibly the dumbest thing I've ever read. You're telling me that there is no such thing as a string in any programming language? That's just dumb.
As to C, read 7.1.1 for the definition of a string:You may not like the definition, but there are strings in C (and in a multitude of other languages).A string is a contiguous sequence of characters terminated by and includeing the first null character. The term multibyte string is sometimes used instead to emphasize special processing given to multibyte characters contained in the string or to avoid confusion with a wide string. A pointer to a string is a pointer to the initial (lowest addressed) character. The length of a string is the number of characters preceeding the null character and the value of a string is the sequence of values of the contained characters, in order.
Quzah.
Hope is the first step on the road to disappointment.
thanks memcpy , I will print it and learn it.
Personally, I suggest that you read up on fgets: the naive way of using scanf to read a string leaves you open to buffer overflow, and correcting it without hard-coding the buffer length is not so straightforward as just using fgets.Originally Posted by tahmod
There is no built-in or standard library string type in C, but the concept of a string exists in C as quzah pointed out. In other programming languages, the concept of a string may also be expressed as a built-in or library string type. Stating that there is no such thing as a "string" in your view also means that there is also no such thing as an "integer", for indeed an "integer" in any programming language is ultimately "simply an area of consecutive memory bytes". This may be true, but it is not useful at all, both in practical computer programming and theoretical computer science.Originally Posted by memcpy
It does not really matter, but I note that it is quzah who linked you to those references.Originally Posted by tahmod
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)