Advertisement
SulphurAge

Untitled

Mar 24th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.55 KB | None | 0 0
  1. void my_get_str (char *str, int lenght) {
  2.  
  3. int i;
  4. char c;
  5.  
  6. for (i=0; i<lenght-1 && (c=getchar()) != '\n' && c != EOF ; i++) {
  7.  
  8.  
  9.     str[i] = c; }
  10.  
  11.             str[i] = '\0';
  12.  
  13. if (c != '\n')
  14. {
  15.     while((c = getchar())!= '\n');
  16. }
  17.  
  18.  
  19. }
  20.  
  21. int my_get_int (int lenght){
  22. int i;
  23. char c;
  24. char* str = (char*)malloc(sizeof(char)*lenght);
  25.  
  26. for (i=0; i<lenght-1 && (c=getchar()) != '\n' && c != EOF ; i++) {
  27.  
  28.  
  29.     str[i] = c; }
  30.  
  31.             str[i] = '\0';
  32.  
  33. if (c != '\n')
  34. {
  35.     while((c = getchar())!= '\n');
  36. }
  37.  
  38. return atoi(str);
  39.  
  40.  
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement