hi guys its my first time doing a c++ program to manipulate shell input
I need to create a c++ program which reads input from this unix shell command >> ls -ali
and then im supposed to count the number of dir,write files.
I am not allowed to use the STAT() function from the library.
I dont know whats wrong with my code below....but it always give me a 0 value output. I think the way i read the input from the command ls -ali is wrong
#include <iostream>
#include <sys/types.h>
#include <unistd.h>
#include <sys/stat.h>
using namespace std;
int main(int argc, char** argv)
{
char input[150];
int writeFile = 0;
int countDir = 0;
mode_t modeCheck;
while (cin >> input)
{
if (modeCheck == S_IFDIR)
countDir++;
if (modeCheck == S_IWRITE)
writeFile++;
}
cout << countDir << endl;
cout << writeFile << endl;
}