Hi I was ask to do a code in c wich read the contenent inside a txt file and display it then after display it they wan't me to tokenize those command and interpretate them in c. I have no experience in c if someone can show me how to read a txt and make c do a command i apreciate it. sorry if my english is not good.

this is mi text file

virtual.txt

int x;

printline("<html><body>");
while(x=!10){
printline("<h1>this is a test<\h1>");
x++;
}

printline("</body></html>");


this is my code to display it's contenents

#include <stdio.h>
#include <stdlib.h>


int main()
{
    FILE *temp;
int c;
    temp=fopen("virtual","r");
    printf("this is the contents of the file :\n\n");
    while((c=getc(temp))!= EOF)
    printf("%c",c);

fclose(temp);

return 0;

}

if someone can show me how to read a txt

this can be done in lots of ways, I suggest searching for examples using fgets, fscanf, fread etc.

make c do a command

what command?

what command?

if you se the text file has some commands in it(that looks kind of c++) i have to make a function
that reads line per line either using fgets or fscanf and translate it to c.

example my first line in virtual.txt is int x; so I have to create something that detec that integer
and create one.
then the printline and so on, I think this is call tokenizing(something like it)

i have to make a function that reads line per line either using fgets or fscanf and translate it to c.

something like this then:
http://www.daniweb.com/software-development/c/code/216411/reading-a-file-line-by-line

example my first line in virtual.txt is int x; so I have to create something that detec that integer
and create one.
then the printline and so on, I think this is call tokenizing(something like it)

it would be tokenizing if your going to further divide the strings from the lines,
check some examples using strtok from the string.h header

I was thinking some thing like this

char *something[200];
char *algo[]="int x;"

while ( fgets ( something, sizeof something, temp ) != "\n" )
{
if(something==algo){
int x;}

else
printf("not found")//but i think this is hardcoding
}

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.