The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
Newsgroups: comp.lang.c
From: Tor Rustad <bwz...@wvtqvm.vw>
Date: Fri, 12 Jun 2009 01:37:10 +0200
Local: Thurs, Jun 11 2009 7:37 pm
Subject: Re: rtf file verification
Cross wrote: return type of getc() is int, not char. Need to check for EOF. > Hello > I am writing a program to verify if it is an rtf file or not. Now, an rtf file > My code is as follows: > //code for connecting to file stream > c=getc(fstream); > if(c!='{'){ '&str' is wrong, could use '&str[0]' or 'str'. > // An rtf file should start with `{\rtf' > fprintf(stderr, "invalid rtf file\n"); > }else if(fscanf(fstream, "%4s", &str), strcmp(str, "\rtf")!=0 ){ using comma operator here is terrible for readability and wrong, in case > fprintf(stderr, "rtf version unspecified.\n"); others have answered that... > // check: if str prints "\rtf", why strcmp returns non-zero value? > printf("%s\n", str); /** > }else{ > // stuff to do > } > return 0; > } > I tried to check the code against an rtf file. The "\rtf" tag check fails * check if file has prefix "{\rtf" */ int is_rtf(FILE *f) { char buf[6]={0}; const char *prefix = "{\\rtf"; if (NULL == fgets(buf, sizeof buf, f)) { return 0==strcmp(prefix, buf); } -- Tor <echo bwz...@wvtqvm.vw | tr i-za-h a-z> You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||