mercredi 4 novembre 2015

IF statement evaluation while reading characters from textfile

Been looking everywhere but couldn't find a good example to fit my needs. Basically I have a textfile that has information with formatting commands.

Textfile:

 .sp 2
 .ce
 Textfile with information and formatting commands.

So this textfile has formatting commands such as ".sp 2" and ".ce".

Now I want the program to detect if a formatting command is in the textfile.

Code so far:

 int main(void) {
 FILE *f = fopen("textfile.txt", "r");
if(!f) {
printf("File not found.\n");
return 1;
}

char c;

int cCount = 0;

while((c = fgetc(f)) != EOF) {
if(c == '\r') continue;
if(c == '\n') c = ' ';

if(c == '.'){ //Now every formatting command starts with a .
  /*
  Need a way to evaluate the next character after "." To check if it's a 
  formatting command or a full stop.
 if(charafter(.)==c){ //pseudocode
 if(charafter(s)==e){
 //Do formatting command linked with ".ce"
 }
 }
  */

}

printf("%c",c);
if((cCount++ > 55) && (c == ' ')) {
  printf("\n");
  cCount = 0;
}
}

  fclose(f);
  return 0;


  }

So essential, what my goal is how to directly evaluate the next character.

I'm sorry if this is a silly question very new C programmer.

Aucun commentaire:

Enregistrer un commentaire