Advertisement
Broatlas

filereadin

Apr 13th, 2016
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.42 KB | None | 0 0
  1. /* PROGRAM:  itr.c
  2.    AUTHOR:
  3.    DATE:
  4.    TOPIC:    SBA
  5.    PURPOSE:  SBA
  6.    NOTES:
  7. */
  8. #include <ctype.h>
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <unistd.h>
  12. #include <string.h>
  13. #define MAX_WORD 45
  14.  
  15. void itr( const char *file, int tr, char *c );
  16.  
  17. /**************************************************************************/
  18. /* MAIN
  19.  **************************************************************************/
  20. int main(int argc, char *argv[] ) {
  21. char *filename[MAX_WORD];
  22. char transform = 'i';
  23. char *point;
  24. int tr = 0;
  25.  
  26. filename[MAX_WORD] = (char *)malloc(sizeof(char) * MAX_WORD);
  27. filename[MAX_WORD] = argv[MAX_WORD];
  28. point = (char *)malloc(sizeof(char) * 1);
  29. point = transform;
  30.  
  31. itr(filename, tr, point);
  32.  
  33.  
  34. free(point);
  35.  
  36.     return 0;
  37. }
  38.  
  39.  
  40. /**************************************************************************/
  41. /* itr:
  42.     const char * file:  filename of the file to be process
  43.     int tr       :  transformation type ( d or s )
  44.     char *c      :  char to be transformed
  45.  **************************************************************************/
  46. void itr( const char *file, int tr, char *c ){
  47.     char *line;
  48.     FILE *fp;
  49. if((fp = fopen(file[1], "r")) == NULL) {
  50.     perror("fopen");
  51.     exit(EXIT_FAILURE);
  52.   }
  53. if((line = (char *)malloc (sizeof(char) * MAX_WORD)) == NULL){
  54.     perror("malloc line");
  55.     exit(EXIT_FAILURE);
  56. }
  57.  
  58. while(fgets(line, MAX_WORD, fp) != NULL){
  59.     printf("%s\n", line);
  60. }
  61.  
  62.  
  63.     return;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement