Thread Ganze Zeile einlesen incl. Leerzeichen: ANSI C (21 answers)
Opened by format_c at 2005-11-17 14:27

esskar
 2005-11-17 16:25
#11273 #11273
User since
2003-08-04
7321 Artikel
ModeratorIn

user image
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
char *getsn(char *buffer, int size) {
     char c;
     char *ptr = buffer;

     while(size > 1 && ptr != NULL && (c = getchar()) != '\n') {
          if(c == EOF) { ptr = NULL; }
          else { *ptr++ = c; --size; }          
     }
if(ptr != NULL) {
*ptr = 0;
ptr = buffer;
}
     return ptr;
}
\n\n

<!--EDIT|esskar|1132237723-->

View full thread Ganze Zeile einlesen incl. Leerzeichen: ANSI C