| | |
can someone please explain???????
![]() |
The getline function is used to read another line of input. Not only can getline read from the regular input data stream, it can also handle input from files and pipes.
The getline function is similar to awk's next statement. While both cause the next input line to be read, the next statement passes control back to the top of the script. The getline function gets the next line without changing control in the script. Possible return values are:
1If it was able to read a line.
0If it encounters the end-of-file.
-1If it encounters an error.
The getline function is similar to awk's next statement. While both cause the next input line to be read, the next statement passes control back to the top of the script. The getline function gets the next line without changing control in the script. Possible return values are:
1If it was able to read a line.
0If it encounters the end-of-file.
-1If it encounters an error.
NOTE: Although getline is called a function and it does return a value, its syntax resembles a statement. Do not write getline(); its syntax does not permit parentheses.In the previous chapter, we used a manual page source file as an example. The -man macros typically place the text argument on the next line. Although the macro is the pattern that you use to find the line, it is actually the next line that you process. For instance, to extract the name of the command from the manpage, the following example matches the heading "Name," reads the next line, and prints the first field of it:
I hope this helps. Sorry if it didnt, but I tried LOL1:oAlsoBesides reading from the regular input stream, the getline function allows you to read input from a file or a pipe. For instance, the following statement reads the next line from the file data:C Syntax (Toggle Plain Text)
# getline.awk -- test getline function/^\.SH "?Name"?/ { getline # get next line print $1 # print $1 of new line.}
getline < "data"Although the filename can be supplied through a variable, it is typically specified as a string constant, which must be enclosed in quotes. The symbol "<" is the same as the shell's input redirection symbol and will not be interpreted as the "less than" symbol. We can use a while loop to read all the lines from a file, testing for an end-of-file to exit the loop. The following example opens the file data and prints all of its lines:
(We parenthesize to avoid confusion; the "<" is a redirection, while the ">" is a comparison of the return value.) The input can also come from standard input. You can use getline following a prompt for the user to enter information:C Syntax (Toggle Plain Text)
while ( (getline < "data") > 0 ) print
C Syntax (Toggle Plain Text)
BEGIN { printf "Enter your name: " getline < "-" print }
dynastyCODERS#1 when it comes to Programming Tutorials, Database designs and discussions, Operating Systems, you name it, check us out and drop us a line to tell us your opinions on any and everything in mind!;)
>1) the difference between getline and gets().
gets is a throwback from ancient C, is impossible to use safely, and should never be used in C++. getline is okay because you can supply a limit for how many characters to read.
>2) why sometimes when getline is used along with some other cin
>statements it skips some of the cin statements
cin will leave a newline character in the stream, and getline uses a newline character as the default termination sentinel. The result is that getline appears to be skipped. If that's not your problem then give us an example with code.
>3)what exactly does the array of structures do?
What array of structures? Your question is incomplete.
gets is a throwback from ancient C, is impossible to use safely, and should never be used in C++. getline is okay because you can supply a limit for how many characters to read.
>2) why sometimes when getline is used along with some other cin
>statements it skips some of the cin statements
cin will leave a newline character in the stream, and getline uses a newline character as the default termination sentinel. The result is that getline appears to be skipped. If that's not your problem then give us an example with code.
>3)what exactly does the array of structures do?
What array of structures? Your question is incomplete.
I'm here to prove you wrong.
![]() |
Similar Threads
- things you cant explain to your nan... (Geeks' Lounge)
- So wierd! anyone could explain this? (Search Engine Optimization)
- Can you explain how to get my content syndicated in Feeds (Advertising Sales Strategies)
- Would someone please explain what folding means? (Geeks' Lounge)
- Please explain to me...dedicated server.. (Networking Hardware Configuration)
- Will somebody please explain value parameters to me!!! (C)
- Please explain debugging (Java)
- COM+: Can anybody explain COM+ Contexts... (VB.NET)
Other Threads in the C Forum
- Previous Thread: abs() function operator
- Next Thread: Can't Display These Topics By Sort?!!
| Thread Tools | Search this Thread |
#include adobe ansi api array asterisks binarysearch changingto char character cm copyimagefile cprogramme creafecopyofanytypeoffileinc createcopyoffile csyntax database directory dynamic execv feet fgets file fork forloop frequency function getlasterror givemetehcodez global grade graphics gtkgcurlcompiling hacking hardware highest histogram i/o include incrementoperators infiniteloop input interest kernel keyboard kilometer license linked linkedlist linux linuxsegmentationfault list locate logical_drives looping loopinsideloop. lowest match matrix meter microsoft motherboard mqqueue mysql number odf opensource owf pattern pdf performance pointer posix probleminc process program programming radix recursion recv repetition research reversing scanf segmentationfault sequential shape socket socketprograming standard string systemcall threads turboc unix user voidmain() wab windows.h windowsapi






