Im trying to make program print whole content of folder by asking user for path to folder where the content is and then by using system() function I want program to make .txt file with output of ls path > systemOutput.txt
and then print it on screen using ncurses lib. There is my code:
#include<stdlib.h>
#include<stdio.h>
#include<ncurses.h>
#include<string.h>
//#include"DevIL/include/IL/il.h"
int main(){
//defining variables
char* userInput;
char *systemInput;
FILE *file;
char c;
//opening ncurses window
initscr();
refresh();
//asking user for folder path which contain photos
printw("EXIF file reader\n\n\n\n\n\n");
printw("Please enter the folder path where the photos are located:\n");
scanw("%s", userInput);
//running bash to print all files in folder
strcat(systemInput,"ls ");
strcat(systemInput,userInput);
strcat(systemInput," > systemOutput.txt");
system(systemInput);
//opening system() output
file=fopen("systemOutput.txt","r");
if(file){
while((c=getc(file))!=EOF){
printw("%c", c);
}
}
if(getch()=='q'){
endwin();
}
}