simple little program that opens a file then reads its contents, when using the debugger asknig for a filename it does not see that file in the same dir it is in, ../Debug/
hard code it in and it still does not see the file.
open a seperate terminal then goto where program is located along with the file, run it and it sees and opens then reads the file.
how to get the debugger to do the same?
// a program to skip to the next line in file if the comment char (#) is encountered
#define CONTENT_LEN 373
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
int main(void) {
/*
if ( argc < 2)
{
printf("no file given\n");
exit(1);
}
*/
char content[CONTENT_LEN];
char filename[10] = "./test";
int i = 0;
// char *filename = NULL;
size_t bufsize = 32;
// char * filename = strdup(argv[1]);
FILE *testfile;
/*
filename = (char *)malloc(bufsize * sizeof(char));
printf("Enter file name for test file\n");
getline(&filename, &bufsize, stdin);
*/
printf("%s\n", filename);
if( access( filename, F_OK ) != -1 ) {
printf("file exist\n");
} else {
printf("file doesn't exist\n");
}
if ( ( testfile = fopen(filename, "r")) == NULL ) {
fprintf(stderr, "Input file cannot be read, aborting.\nDoes it exist?\n");
return 1;
}
while ( fgets(content, CONTENT_LEN, testfile) != NULL ) {
for ( i = 0; content[i] != '\0'; i++ ) {
if (content[i] == '#')
{
int f = i;
if ((content[--f] == ' ') && (content[++f] == ' ')) {
break;
} else {
printf("%s\n", content);
printf("%c", content[i]);
}
}
/*
if (( content[i] == '#' ) && ( content[--i] != '\0' || content[--i] != ' ' || content[--i] != '\n'))
printf("line[%s]\n", content);
*/
}
// break; // (4) for loop stops after not equal to a space and displays the first char of the line, but because of the nested if, also looks for the hash
}
// printf("%i < %i (%c) ? %s (loop exited)\n", i, content[i], content[i], i<content[i] ? "True" : "False");
fclose(testfile);
return 0;
}