Hello guys,
I have a huge semester project and i would require some help(if you want of course) with coding. I have to mention that i am not a code expert so my question might sound a bit silly.
So here we are. What i want to do is a part of my whole project. At first i would like my code to read all txt files from a folder and then write a list of the files it read to an another txt file. Than i would like to write a function which will read the list from the txt file and store there names in a variable.
So here is the code i came up with so far but is doesn't work. Actually it stucks all the time and i get a message from windows saying "this program has stopped responding and it will be terminated..!!!"
Can you please help me...?
Thank you
I have a huge semester project and i would require some help(if you want of course) with coding. I have to mention that i am not a code expert so my question might sound a bit silly.
So here we are. What i want to do is a part of my whole project. At first i would like my code to read all txt files from a folder and then write a list of the files it read to an another txt file. Than i would like to write a function which will read the list from the txt file and store there names in a variable.
So here is the code i came up with so far but is doesn't work. Actually it stucks all the time and i get a message from windows saying "this program has stopped responding and it will be terminated..!!!"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <dirent.h>
int main (void)
{
DIR *dp;
struct dirent *ep;
FILE *fp;
char name[50];
fp = fopen("AirfoilList.txt","a");
dp = opendir ("C:/path/to/my/folder");
if (dp != NULL)
{
while ((ep = readdir (dp)))
puts (ep->d_name);
fputs(ep->d_name,fp);
(void) closedir (dp);
}
else
perror ("Couldn't open the directory");
return 0;
}
Can you please help me...?
Thank you