getline « Development « C Q&A

Home
C Q&A
1.assembly
2.buffer
3.Card
4.Cast
5.compile
6.console
7.const
8.constructor
9.database
10.Date
11.Debug
12.Design
13.Development
14.DLL
15.encrypt
16.enum
17.eof
18.Event
19.fork
20.Format
21.gcc
22.gdb
23.graph
24.graphics
25.gui
26.Holiday Event
27.image
28.IP
29.iterator
30.macro
31.makefile
32.malloc
33.Menu
34.mysql
35.network
36.openssl
37.operator
38.password
39.pipe
40.preprocessor
41.printf
42.pthread
43.Regular expression
44.scanf
45.semaphore
46.SerialPort
47.server
48.Socket
49.sql
50.SQLserver
51.sscanf
52.std
53.stdin
54.stdout
55.stl
56.strcmp
57.stream
58.switch
59.Template
60.thread
61.timer
62.unix
63.video
64.Virtual
65.visualstudio
66.winapi
67.windows
68.xml
C Q&A » Development » getline 

1. Are there alternate implementations of GNU getline interface?    stackoverflow.com

The experiment I am currently working uses a software base with a complicated source history and no well defined license. It would be a considerable amount of work to rationalize things ...

2. getline check if line is whitespace    stackoverflow.com

Is there an easy way to check if a line is empty. So i want to check if it contains any white space such as \r\n\t and spaces. Thanks

3. I need to know if I am using getline correctly    stackoverflow.com

I am using the getline() function in C and it keeps giving me seg faults when I use it more that once, as in for an array. Here is how I've ...

5. How to use Getline?    bytes.com

I'm working with a file. I want to write a code that returns a particular string located somewhere in the file. I have the starting position of the desired string and it's length so I thought that i can use getline. but i'm not sure how to do that.For using get line can i use the position of the pointer of ...

7. getline problems    bytes.com

hi, i'm using code like this string s while(getline(cin,s)){ process(s); } // this is the last line process(s); process does some replacement and rescanning. The problem is i can't strip or add newlines. So i don't know whether the lastline contains a '\n' or it was just EOF. I can't read the whole buffer as it is too huge and some ...

8. getline() problem    bytes.com

I am learning malloc() and realloc() and I got the code from here: http://www.eskimo.com/~scs/cclass/notes/sx11c.html #include #include enum MAXSIZE { ARRSIZE = 1000 }; int main( void ) { char line_of_chars[ARRSIZE]; int *ip; int nallocs, nitems; nallocs = 100; ip = malloc(nallocs * sizeof( int )); if( ip == NULL ) { fprintf( stderr, "out of memory\n"); exit(EXIT_FAILURE); } nitems ...

9. Help with getline    bytes.com

10. getline() and newlines    bytes.com

I have a text file with mixed carriage returns ('\n' and '\r\n'). On Linux, both the std::string getline() global function and the std::iostream getline() member function are keeping some of the newlines in the result (I suspect they look only for the '\n'). * Is there a quick way I can tell either function to gobble up both Windows-style and Unix-style ...

11. getline and deleteline    bytes.com

Hi, I am reading out a text fileusing following lines: [C++] ifstream ifs (RECORD_FILE, ifstream::in ); while( getline(ifs,recordStr) ) { // while until file is empty cout << "Read from file: " << recordStr << endl; recordStrQueue.push(recordStr); // push the read line into the queue } ifs.close(); [/C++] Now i would like to delete the line in the file as soon ...

12. getline failbit?    bytes.com

check it at http://rabbit.eng.miami.edu/info/functions/errors.html Arul, Thanks for that page. It looks like it could be invaluable in the future. I tested the errno value and it was reported as being 2 (file/directory not found). I thought that was a little odd as obviously the previous line checks to see if the file was opened succesfully. Therefore I tried resetting the errno ...

13. getline();    bytes.com

if you have a string str="welcome to thescripts\nc++,c"; and another string str2; if you used the function getline(str,str2) str2 will be "welcome to the scripts" (not including the '\n'. if you want to use cin in the getline function you just put it in the first parameter. good luck and i hope i was helpful

14. A big problem with getline    bytes.com

Hi, I am trying to read two string, one after another, and before I read the second one I clean the buffer using cout.flush(), but I don't know why the program does not read the second string, not even the the third value using cin, Please I need your help. . . . . . this is the program: #include #include ...

15. Getline problem    bytes.com

16. break from getline    bytes.com

Why do you need to tell cin to stop blocking? You have 2 threads, one blocks on cin and the other does its work. As long as the blocking cin thread doesn't stop the whole process (it shouldn't) and the other thread does not need to access cin, you should have no deadlock issues. You should be able to interrupt a ...

17. Your getline is better than mine    bytes.com

18. my getline is better than yours    bytes.com

P: n/a Rosario do you like the "GetLine_m" function i have written today? How many errors do you see? i have try only the option for to load the all [text] file in a string not the option to load a line "\n" ended so it should be full of errors [but because i have the "len" i can load with ...

19. Getline and for Loops    bytes.com

There are 2 things I see wrong with this code: 1) You're outputting the contents of scores before you give them any values, so this is going to clutter up your output screen with garbage values. 2) You're using a mixture of getline and cin >> statements, which always leads to the following problem: When cin is inputting normally (i.e. cin ...

20. Bug in SosMan's getline_test    bytes.com

Friar Tuck I believe I have found a bug in Dr Sosman's getline_test program, which is one of the official newsgroup programs. Debugging information follows. $ gdb ./getline_test GNU gdb 6.3 Copyright 2004 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under ...

21. Stringstreams Getline    bytes.com

Hi, How do i use stringstreams getline function to extract lines from an existing string? Say i have: string strlist = "line1\r\nLine2\r\nLine3\r\n"; I want to extract each line out into a vector array of strings, but i cant get stringstream working :( This is the sort of code i have tried: // istream& getline (char* s, streamsize n ) stringstream MyStream; ...

22. Please help me with this cin.getline() problem    bytes.com

If you put 20 characters on the standard input buffer and then ask for only 9 of those characters then you have 20-9 characters left on the buffer. So the next time you ask for 9 more characters you are getting 9 more from the original 20-9. If you want the buffer to be clear each time after you call a ...

23. abt cin.getline()...    bytes.com

i m using cin.getline() to input names of objetcs of a class... i am using dynamic number of objects but durn my loop to input names of different object(char* name is a member of this class) for the first time everythn is OK but for successive times it is by passin the cin.getline() but excutin othr commands.... a schematic sketch of ...

24. how to handle Control-D in getline ?    bytes.com

Hi, I have a program where I read a lot of user data. How can I handle the case where the user press control-d ? Is it possible to disable control-d or re-open the cin ? I have made a small example which hopefully shows my problem. Regards Martin #include #include int main() { std::string command; while (true) { ...

25. Question about cin.getline()    bytes.com

use dynamically allocated char streams... streamsize n =0; //u can substitute streamsize by int/long as u like cout<<"ENTER MAXIMUM ALLOWED CHARECTERS :"; cin>>n; char* some_string =new char; cin.getline(some_string, n); // the 3rd parameter delimiter is optional code.... delete some_string; // relesing memory ro free store some_string =0; u can even bypass this limitation f specifyn the streamsize beforehand but thn u ...

26. getline and C    bytes.com

Hello, I am new at computer programming and I am having trouble using getline() in C. I use an input file that contains 12 variables on every line. From the printf statements below, I notice that scanf, although risky, does the job correctly. However, getline skips the first line from the input file and evaluates the last line twice. Do you ...

27. getline() special    bytes.com

Hey, first of all sorry for my bad english, but I'm from Germany I found something special in the getline() function, I don't understand. If I use the getline function in case of an Excel-sheet or an image - to get the image-data - the getline function breakes after a NULL termination ( \0 ) fstream oFile_e; oFile_e.open("BAB.xls",ios::in); oFile_e.getline(chTest, 100,'\n'); BAB.xls ...

28. getline problem    bytes.com

29. getline with cin problem -- multiple returns needed    bytes.com

Chris std::string randomStuff; std::getline(std::cin, randomStuff); > works on unix, but on windows, it requires the user to hit the enter key *twice* before it continues past the getline. I tried changing the getline to > std::getline(std::cin, randomStuff, '\n'); > but that didn't help. Any ideas? Please post a complete and minimal ...

31. Segmentation fault on end of loop... (getline)    bytes.com

hi, im new here... um, this code works except that, at the end of the loop, i always get a "Segmentation fault". Can anyone help me on this? using GNU C: ..... FILE *fp; fp = fopen("./prg.c", "r"); char *line; int x=1; int nbytes = 100; while(getline( &line, &nbytes, fp ) != -1) { printf("%d: %s", x, line ); x++; } ...

32. getline and copy funcitons    cboard.cprogramming.com

Can someone explain me getline() and copy() ? I've tried to read and read it again but I can't understand it. This is a code from "The C Programming Language, Kernighan and Ritchie" Code: #include #define MAXLINE 1000 /* maximum input line lenght */ int getline(char line[], int maxline); void copy(char to[], char from[]); /* print the longest input line ...

33. Non-locking getline using select?    cboard.cprogramming.com

First of all, I'd like to tell you all I'm not an experienced C programmer in particular... But I do my best (: So here is my situation: as a way to learn how programming networking applications work, I'm writing this little client/server-based chat program. It is already starting to look like something. However, I can't get one thing to work ...

34. conflicting types for getline() fix    cboard.cprogramming.com

Code: #include #define MAXLINE 1000 int getline(char line[], int maxline); void copy(char to[], char from[]); int main(){ int len; int max; char line[MAXLINE]; char longest[MAXLINE]; max = 0; while((len = getline(line, MAXLINE)) > 0){ if(len > max) { max = len; copy(longest, line); } if(max > 0){ printf("%s", longest); } } return 0; } int getline(char s[], int lim[]){ int ...

35. getline problem    cboard.cprogramming.com

#include #include #include int getline_program(char *buffer,int num) { fgets(buffer,num,stdin); return strlen(buffer)-1; } void save_it(char *buffer,char *buffer1) { int i,x; for(i=0,x=0 ; buffer[i]=buffer1[x] ; i++ ,x++); } int main(void) { char name[100]; char *buffer; int x,longest,swap; buffer=malloc(sizeof (char)*100); for(;;){ x=getline_program(name,sizeof name); save_it(buffer,name); longest=x; swap=longest; printf("x=%d\t longest=%d\n %d\n",x,longest,swap); if(x>longest) { puts("its longer: preforming functions\n"); free(buffer); buffer=malloc(sizeof (char)*100); longest=x; save_it(buffer,name); printf("Your ...

36. getline error    cboard.cprogramming.com

Code: int main(int argc, char *argv[]){ char* tester = "makefile"; char* tester1 = "Makefile"; if (argc == 1){ fprintf(stderr, "memake: *** No targets specified and no makefile found. Stop.\n"); return 2; } else if (strcmp(argv[1], tester) == 0 || strcmp(argv[1], tester1) == 0){ char* file_to_read = argv[1]; FILE* fr = fopen(file_to_read, "w"); if (fr == NULL){ fprintf(stderr, "%s: trying to open ...

37. help with getline.    cboard.cprogramming.com

38. cin.getline help    cboard.cprogramming.com

39. delimiter-terminated getline?    cboard.cprogramming.com

i have two problems actually: 1) in c++, you can use the 'getline' function to read in a line that is terminated with a specified delimiter..is this at all possible in c? I am assuming that i'd have to create a loop and use getc (this is all reading input in from a file). 2) this line of code does not ...

40. getline in C?    cboard.cprogramming.com

Thanks for all your help on this board I really appreciate it and before I begin Im only asking/making some comments. Im not here to argue, fight, or anger anyone. I just want to say a few things on the silent n00bs behalf. SOME of us do read books, search boards, and are very interested in really learning this stuff we ...

41. getline to divide    cboard.cprogramming.com

42. Getline help    cboard.cprogramming.com

The code as of now is: #include char * getstring(char * string,int max_chars) { char responce; char * pstring; pstring = string; int number; while ((responce = getchar()) != '\n') { if (number < max_chars) { *pstring++ = responce; number++; continue; } else { break; } } *pstring = '\0'; return string; } int main(void) { char ff[10]; getstring(ff,10); puts(ff); ...

43. Getline(cin,str) not working?    forums.devshed.com

When i write this code it does not take anything for input for the original string and automatically goes to the next cin... void substring() { //declare variables string str; int b, length; //taking input from user(keyboad) getline(cin,str); cout << " Enter beginning position : "; cin >> b; cout << " Enter length of substring : "; cin >> length; ...

44. Program skips over getline() for no reason    forums.devshed.com

Original - c++ Code #include #include using namespace std; //Return the ending result in a file double lastResult() { double Line=0; ifstream MyFile("Session.txt"); while (!MyFile.eof()) { MyFile>>Line; } return Line; } //Write to the end of a file void writeFile(string Input) { ofstream myfile("Session.txt",ios::app); myfile << Input << endl; } //Clear text on screen void clearScreen() { for (int ...

45. CIN getline problem and ignore statement    forums.devshed.com

CIN getline problem and ignore statement Code: #include #include //getch() header file #include #include using namespace std; //-------------------------------------------------------- struct courseSection{ char sectionNumber[6]; //first 3 character, last 3 digit char startTime[6]; char startDate[10]; char roomNumber[4]; // char courseNo[6]; courseSection *next; }*startCourseSection=NULL; //------------------------------------------------------- struct course{ char courseNumber[7]; char title[20]; char creditHours[10]; course *next; }*startCourse=NULL; //-------------------------------------------------------- struct student{ int studentID; ...

46. Error in getline() Argument    forums.devshed.com

47. Getline()    forums.devshed.com

Does anybody know what: getline(cout, business); does? The text I am reading has it in an example but yet no explanation of it. There are other forms of it with which I am familiar when taking input from the user and getting the whole line up to /n. However, this? I'm not sure... thx PS - How do I respond to ...

48. In C, do getline and getdelim exist?    forums.devshed.com

I am beginning to learn to program in C.* In one of the tutorials that I am reading it says that when doing I/O you should use getline and getdelim.* It says that these are GNU extensions?* It also says that using other I/O functions is not as safe; such as gets().* The problem I have is that in the other ...

49. Cin.getline problem    forums.devshed.com

50. C-style getline.    forums.devshed.com

Oh sorry, I think I see it now. Check the docs for the getline() function. Bet it stops inputing data when it reaches the specified end-of-line character. That means you never get to the end of file if there is new-line character at the end of the first line of text. You need to check the ruturn value from getline() and ...

51. Difference between 'gets' and 'cin.getline'    forums.devshed.com

Hey guys, I done a bit of C++ for college when I was there, so I thought I would take it up again to see if I could still make a wee program with it (not that it does anything much ). Everything seems to be going well with it, but there is one thing that has been bothering me. When ...

52. cin.getline() not working properly    forums.devshed.com

53. getline fn    forums.devshed.com

i almost have my roman to numeral prog sorted out. the last thing i need is to get rid of an input1 error. Code: int FindNumberOne () { char input1; float value1 = 0.0; cin.get(input1); while ( intput1 != '\n') { if ( input1 == 'M' ) value1 = value1 + 1000; else if ( input1 == 'D' ) value1 = ...

54. getline()    forums.devshed.com

long videoNum; char videoName[1]; cout << " -- Current Record -- " << endl; cout << " What is the Video Number?: "; cin.getline (videoNum, EOF); cout << " What is the Video Name?: "; cin.getline (videoName, EOF); cout << " -- New Record -- " << endl; cout << " What is the Video Number?: "; cin >> videoNum2; cout ...

55. cin.getline problems    forums.devshed.com

Nellie, you say this doesn't work and that doesn't work, but one always has to pry your code out of you in order to have a look and see what's wrong. Please re-read the post for new users regarding tips about how to ask questions. Actually, it revolves around providing information, as information is the source of knowledge.

56. Why does it skip first getline command?    forums.devshed.com

Hi, everyone I don't get any warning or error. I'm using Visual Studio.net The problem I have with this program is that when I run it, It automatically skips first cin.getline function.( cin.getline (name,256) so I choose 1 when I run the program then the following happens Enter your name: Enter your favourite movie: (then wait for responce from keyboard) I ...

57. getline argument error    forums.devshed.com

You can read the data into a string. There is more than one 'getline.' I recommend the string class overloaded one for strings. Refer to your documentation for correct usage. I would suggest that advising your user to make sure he/she names the correct file is no substitute for checking the open operation to ensure it succeeded prior to making an ...

58. Small problem with getline operation    forums.devshed.com

problem solved, I've been tearing my hair out for over 12 hours on this one, I'm indebted! Thanks a million. The reason I'm mixing getch() with iostream stuff is because I'm a student who's only been doing c++ for 3 months, and programming lecturers seem to be notoriously bad. This is the last c++ project I'll ever have to do, too. ...

59. cin.getline repeats cout question    forums.devshed.com

#include using namespace std; int main() { char *name = new char[26]; // this zeros out the newly allocated memory on my system but it should not be assumed to do so everywhere name[0] = 0; // make sure strlen calculates to < 1 the first time while (strlen(name) < 1) { cout << "Enter your name: "; cin.getline(name, 25); ...

60. successive getline()    forums.devshed.com

I realize it's a new concept that hasn't been mentioned in the forum before, but if it were me and I were puzzled about my input failures, my code would have a number of calls following the getline statement to the various functions which reveal the status (good, bad, et al) of the stream.

61. getline() doesn't interrupt loop iterations    forums.devshed.com

I would've thought that a getline() would wait for some form of input from the keyboard in all cases, but apparently this isn't true. When I use a getline(), not inside of some sort of looping structure, it works fine. The problem is that when it's inside some sort of control structure the program doesn't wait for some sort of input. ...

62. getline is killing me    forums.devshed.com

Hey everyone! I've been pulling my hair out over this problem for the past hour.. I've used getline before but this time something is up.. here is a snippet of my code: cout << "Please type a yes/no question that will distinguish a "; cout << correct_animal << " from a " << guess_animal << "."; cout << "Your question: "; ...

63. Help with getline and cin!!    forums.devshed.com

64. getline(cin, text)    forums.devshed.com

Hi, I am unable to make the function getline(cin, text) work correctly. In Ivor Horton's Beginning C++(p.206), he says the function is declared in the string header file and will read in a line of input from cin up to the point when a newline character is read. I find that after I enter some text and hit return, the cursor ...

65. Reading whitespace using getline. Printing garbage to screen    forums.devshed.com

having problems reading in white space using getline.. Getting lots of garbage when displaying them to screen. Here is data file i used. 34 Paul Smith West Seneca 54 Rick Smith East Side Code: #include #include #include #include void main() { int employee; char name[50]; char city[50]; ifstream infile; ofstream outfile; infile.open("data.txt"); while ...

66. Problem With getline.cin    forums.devshed.com

I have been writing a simple calender program to test out my knowledge of C++ so far. If you could compile the code below, you'll see the problem that I'm having. It's very, very strange and anyone who would correspond would be welcome. #include #include #include using namespace std; enum evenodd { EVEN, ODD }; int numofdays; int ...

67. parsing information from getline    daniweb.com

I'm having a problem parsing information stored in the buffer after a getline command. I have a file with data in the format: 1310 76102 C 5 27 2011 6 26 2011 5 R R 8.00 20.00 F R 8.00 25.00 150 165 I would separate everything using white space as a delimiter, but the information isn't always the same. i.e. ...

68. Problems with getline() on os x    daniweb.com

#include #include #include #include #define _GNU_SOURCE #include #include #include #include #include #include #include #include //********************************************************************************************************* void Help(const char* program_name) { printf("\n\t*************HELP*************\n"); printf("(C) Juraj Stefanicka\n"); printf("\nTento program sluzi na rekurzivne prehladavanie adresarovej strukturi zadanej argumentom programu.\n"); printf("\nSpustanie programu: \n\t%s [-c | --count] []\n\n", program_name); printf("Ak nezadate ziadny prepinac program vypise ...

69. Getline causing SIGSEGV    daniweb.com

70. getline error    daniweb.com

#include #include # define NEWLINE '\n' int main() { static const char filename[] = "Bond.in.txt"; FILE *file = fopen(filename, "r"); if ( file != NULL ) { char line [ 200 ]; while ( fgets ( line, sizeof line, file ) != NULL ) /* read a line */ { fputs ( line, stdout ); /* write the line ...

71. Using getline in C    daniweb.com

72. Replace , with | after getline/ignore.    codeproject.com

This is C code, not C++. That makes things a lot more complicated. If you were using C++, I'm sure there would be CSV parsing classes you could use. The rule is simple, you look for commas that are outside quotes. You could write an iostreams reader to do that for you, for example, and change the delimiter as it goes. ...

73. getline ( cin, string1) problem    codeproject.com

74. Question about cin.getline()    tek-tips.com

Why doesn't this program allow me to input anything into name? Am I misusing cin.getline()? Is there a more effective way to accomplish what I am trying to do here? #include #include struct database{ int integer; char name[50]; char notes[200];} record[100]; void main(){cout << "Enter an integer: ...

75. Need help with Getline    tek-tips.com

Hi,I'm having trouble getting getline to work. Keeps giving me segmentation faults. I have made a short program to debug what I'm doing wrong. This code is also giving me segmentation faults.Can some tell me what I'm doing wrong? Attached is the code:#include main(){ char *cptr = (char *) malloc(sizeof(char)); getline(cptr,10,stdin);}Thanks in advance

java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.