Guest User

Untitled

a guest
Jun 19th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. FILE *f;
  2. char line[LINE_SIZE];
  3. char *lines;
  4. int num_righe;
  5.  
  6. f = fopen("spese.dat", "r");
  7.  
  8. if(f == NULL) {
  9. f = fopen("spese.dat", "w");
  10. }
  11.  
  12. while(fgets(line, LINE_SIZE, f)) {
  13. num_righe++;
  14. lines = realloc(lines, (sizeof(char)*LINE_SIZE)*num_righe);
  15. strcpy(lines[num_righe-1], line);
  16. }
  17.  
  18. fclose(f);
  19.  
  20. spese.c:29: warning: assignment makes integer from pointer without a cast
  21. spese.c:30: warning: incompatible implicit declaration of built-in function ‘strcpy’
  22. spese.c:30: warning: passing argument 1 of ‘strcpy’ makes pointer from integer without a cast
  23.  
  24. FILE *f;
  25. char line[LINE_SIZE];
  26. char **lines = NULL;
  27. int num_righe = 0;
  28.  
  29. f = fopen("spese.dat", "r");
  30.  
  31. if(f == NULL) {
  32. f = fopen("spese.dat", "w");
  33. }
  34.  
  35. while(fgets(line, LINE_SIZE, f)) {
  36. num_righe++;
  37. lines = (char**)realloc(lines, sizeof(char*)*num_righe);
  38. lines[num_righe-1] = strdup(line);
  39. }
  40.  
  41. fclose(f);
  42.  
  43. char * strcpy ( char * destination, const char * source );
  44.  
  45. strcpy(lines[num_righe-1], line);
  46.  
  47. strcpy(lines + (num_righe-1), line);
  48.  
  49. lines = realloc(lines, (sizeof(char)*LINE_SIZE)*num_righe);
  50.  
  51. if (!lines) //MUST HANDLE NULL POINTER!!
  52.  
  53. /* string copy code here*/
  54.  
  55. fscanf(f, "%sn", line[index]);
  56. index++;
Add Comment
Please, Sign In to add comment