i wan to do c++ program in ubuntu that able to write a summary on the directory example is
drwx-x John 4096
d-w--x John 14
lrwx-x John 2300
How to i use array to put per column into array then access them so i can generate a report so it will be like this
Summary
Total directories = 2 ( the number of d in front determine it)
total link files = 1 ( the number of l in front determine it)
Name of user = John
Total size = 6410 (the total size of last column)
for now is i using char to determine the directories and link file
this is what i done to find the directories and link, but i cant use char method to grab name and calculate total size...anyone can tell me any method to generate the report...ty for all help
This is probably the sloppiest code I've ever written, I am sure this code can be written in much more elegant manner. I wrote it in 10 min just to give you some idea as to what you have to do.
If your going to use cin.getline(), make sure you specify a maximum limit. Otherwise your going to create a cascading buffer-overflow through your application. Especially as you have used functions such as strcpy() that do no bounds-checking.
kevin,i wanna ask you, for these piece of code , it could only read the first letter of its flag becos of the string token, may i know wat shld i do if i want to read the second letter or other letter of that flag .
Hey! Sorry for not replying for so long. Anyways if you'll just use
p instead of temp = *p
(Of course, considering you are not assigning this value to temp)
You'll get entire string. And if you want to access other characters in that string then just do p[index]
So, the code can be rewritten as:
Now p will have entire string, and to access individual characters in the string just use p[index]. Make sure that index is within the string length, otherwise it will return a garbage value, since C does not do array bound checking.
Hope this helps.