Hey everyone, im a first time programmer, electrical engineer major at UCSD and well I have to learn C. I'm not really looking for answers, just ideas and help on my program, its my first assignment in programming ever and my professor is for lack of a better term, an Idiot. He can't explain how the program is supposed to work or what i should be trying to use in it so I've had to resort to getting help on the internet which is why im here.
This is my first assignment, it is quite a beast if you've never touched code before, well at least to me its a beast. It pretty much says open .txt file which will list to you several .c file in which i must print out the first comment, count every line of comments, cound every blank line, and every line of actual coding. Take these numbers and write them into a new .txt file which needs to be organized.
______ Does the lab compile and start running?
______ Does the lab print to the screen: ECE 15 Lab 1, and then the name of each lab
partner on a separate line?
Partner names:____________________________________________ ______
______ Does the lab ask the user for the name of a file (the names file) to open, then
accept that input?
______ Does the lab print to the screen the first line of text in the opened names file?
______ Does the lab then use that line as another filename to open (the program file)
and print to the screen the first comment, /* */ or // type, it finds?
______ Does the lab loop through the program file, printing to the screen all comments
found?
______ Does the lab print to the screen the total number of comments, comment characters,
comment lines, and non-blank non-comment lines found in the file?
______ Does the lab also record the program filename and the above information to a
text file: results.txt, all on a single line?
______ Does the program correctly loop over all program files in the names file, printing
their results to the screen and appending them to results.txt.
______ Are the data in results.txt formatted in neat vertical columns?
This is my code and as you can imagine it doesnt work, if you comment it out before Read2 is trying to be set to read the imbedded files in the .txt you can get input which was pretty simple. With the loop below i was trying to read through the imbedded file and print out the comments and of course it doesnt work.Code:#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
int main(int argc, char *argv[])
{
printf("ECE 15 Lab 1\n\nJoel Trost\n\n");
int i = 0;
int counT;
char s[81];
char SF[81];
FILE *fRead, *Read2;
printf("Please Input A Proper File Name: ");
scanf("%s", s);
fRead = fopen(s, "r");
fgets(s, 81, fRead);
printf(s);
Read2 = fopen('%s', "r");
Do
{
if(Read2[i[ == '/' && Read2[i++] == '/')
{
fgets(SF, 81, Read2);
printf(s);
{
if(Read2[i] == '/' && Read2[i++] == '*')
{
fgets(SF, 81, Read2);
printf(s);
}
else if(Read2[i] == '*' && Read2[i++] == '/')
Break 0;
While(Read2[i] != 'null')
}
My main problem is i dont know how the logic works and have had difficulty in finding examples of reading files in C mainly due to no one actually does read files with C, well so im told. If anyone can please help me, explain some idea of what i should be using or what command lines i should toy around with any and all help would be much appreciated. I'm here to learn and being completely clueless as to how the entire process works im completely lost.
Thanks again.