fork download
  1. struct dirent *pDirent;
  2. DIR *pDir;
  3. char filePath[500] = "testDir/testDir1/";
  4. pDir = opendir ("testDir/testDir1");
  5. while ((pDirent = readdir(pDir)) != NULL)
  6. { printf("*******");
  7. printf("The filePath is: %s \n", filePath);
  8. printf("dirent is %s \n", pDirent->d_name);
  9. if (strcmp(pDirent->d_name, ".") == 0 || strcmp(pDirent->d_name, "..") == 0)
  10. {
  11. printf("get that shit %s\n", pDirent->d_name);
  12. continue;
  13. }
  14. strcat(filePath, pDirent->d_name);
  15. printf ("[%s]\n", filePath);
  16. printf("Is regular? %d \n", IsRegularFile(filePath));
  17. printf("Is dir? %d \n", isDirectory(filePath));
  18. strcat(filePath, "/");
  19. printf("%c %c %c \n",filePath[strlen(filePath) - 4], filePath[strlen(filePath) - 3],filePath[strlen(filePath) - 2]);
  20. if (filePath[strlen(filePath) - 4] == 't' && filePath[strlen(filePath) - 3] == 'x' && filePath[strlen(filePath) - 2] == 't') //add check for length and .txt
  21. {
  22. printf("File is txt\n");
  23. break;
  24. }
  25. printf("end of loop\n");
  26. }
  27. printf("The filePath is: %s \n", filePath);
  28. strcpy(input_file_name, filePath);
  29. printf("input_file_name is: %s \n", input_file_name);
  30. //free(input_file);
  31. //char input_file_name2[] = "testdir/testFile.txt";
  32. FILE *input_file2 = fopen(input_file_name, "r"); printf("line 127 \n");
  33. fseek(input_file2, 0, SEEK_END);printf("line 127 \n");
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c:2:5: error: unknown type name ‘DIR’
     DIR *pDir;
     ^
prog.c:4:5: warning: data definition has no type or storage class [enabled by default]
     pDir = opendir ("testDir/testDir1");
     ^
prog.c:4:5: warning: type defaults to ‘int’ in declaration of ‘pDir’ [-Wimplicit-int]
prog.c:4:5: error: conflicting types for ‘pDir’
prog.c:2:10: note: previous declaration of ‘pDir’ was here
     DIR *pDir;
          ^
prog.c:4:5: warning: implicit declaration of function ‘opendir’ [-Wimplicit-function-declaration]
     pDir = opendir ("testDir/testDir1");
     ^
prog.c:4:5: error: initializer element is not constant
prog.c:5:5: error: expected identifier or ‘(’ before ‘while’
     while ((pDirent = readdir(pDir)) != NULL)
     ^
prog.c:27:12: error: expected declaration specifiers or ‘...’ before string constant
     printf("The filePath is: %s \n", filePath);
            ^
prog.c:27:38: error: expected declaration specifiers or ‘...’ before ‘filePath’
     printf("The filePath is: %s \n", filePath);
                                      ^
prog.c:28:5: warning: data definition has no type or storage class [enabled by default]
     strcpy(input_file_name, filePath);
     ^
prog.c:28:5: warning: type defaults to ‘int’ in declaration of ‘strcpy’ [-Wimplicit-int]
prog.c:28:5: warning: parameter names (without types) in function declaration [enabled by default]
prog.c:28:5: warning: conflicting types for built-in function ‘strcpy’ [enabled by default]
prog.c:29:12: error: expected declaration specifiers or ‘...’ before string constant
     printf("input_file_name is: %s \n", input_file_name);
            ^
prog.c:29:41: error: unknown type name ‘input_file_name’
     printf("input_file_name is: %s \n", input_file_name);
                                         ^
prog.c:32:5: error: unknown type name ‘FILE’
     FILE *input_file2 = fopen(input_file_name, "r"); printf("line 127 \n");
     ^
prog.c:32:5: warning: implicit declaration of function ‘fopen’ [-Wimplicit-function-declaration]
prog.c:32:31: error: ‘input_file_name’ undeclared here (not in a function)
     FILE *input_file2 = fopen(input_file_name, "r"); printf("line 127 \n");
                               ^
prog.c:32:61: error: expected declaration specifiers or ‘...’ before string constant
     FILE *input_file2 = fopen(input_file_name, "r"); printf("line 127 \n");
                                                             ^
prog.c:33:24: error: expected ‘)’ before numeric constant
     fseek(input_file2, 0, SEEK_END);printf("line 127 \n");
                        ^
prog.c:33:44: error: expected declaration specifiers or ‘...’ before string constant
     fseek(input_file2, 0, SEEK_END);printf("line 127 \n");
                                            ^
stdout
Standard output is empty