Home / Pastebin / ApBnW0VXZGBH20XW6bbukEGLiFxdOIH6
Back to Pastebin

Have to type an extra "enter" whie i tried to finish inputing

Anonymous  ·  March 27, 2026, 3:43 p.m.  ·  6 views
C

							
1 char * get_string(int str_size){
  2     char * tmp = (char*)malloc(str_size);
  3     int i=0;
  4     char ch;
  5     if(tmp==NULL)
  6         return NULL;
  7 
  8     while(i<str_size-1 && (ch = getchar())!='\n'){
  9         tmp[i] = ch;
 10         i++;
 11     }
 12     tmp[i] = '\0';
 13 int garb;
 14 if( (ch=getchar())!='\n' && ch!=EOF){
 15     while((garb = getchar())!='\n' && garb!=EOF);
 16 
 17 
 18 }
 19 return tmp;
 20 }
 21 
 22

Actions

Paste Info

ID: ApBnW0VXZGBH20XW6bbukEGLiFxdOIH6
Language: C
Size: 474 chars
Expires: Never