Advertisement
m1o2

GetString m1o2 fxp elsf captinmichael

Jan 24th, 2012
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.63 KB | None | 0 0
  1. char *GetString(void* inputSource ){
  2.  
  3.     int size=0,input;
  4.     char *string = NULL;
  5.  
  6.     while( fscanf(inputSource,"%c",&input) == 1 && (char)input!='\n' && input!=EOF){
  7.  
  8.         if( (string = realloc(string,size+2)) == NULL ){
  9.             fprintf(stderr,"\n\n Faild To (re)Allocate Dynamic Memory ! \n\n");
  10.             WaitForResponse;
  11.             exit(1);
  12.         }
  13.  
  14.         if( input == '\b' ){
  15.             if( size ){
  16.                 string[size] = '\0';
  17.                 string[size+1] = '\0';
  18.                 size--;
  19.                 putchar('\b');
  20.                 putchar(' ');
  21.                 putchar('\b');
  22.             }
  23.         }
  24.         else{
  25.             *(string+size) = input;
  26.             size++;
  27.         }
  28.     }
  29.  
  30.     if( !size )
  31.         return NULL;
  32.  
  33.     *(string+size) = '\0';
  34.  
  35. return string;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement