[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Bugg eller feature ??



Hej !

Har knappat ihop ett litet program som skall bli lite större.

Tyvärr, så har jag kompileringsproblem med det. gcc påstår följande:
test.c:52: Warning: comparison is always 0 due to limited range of data type.
test.c:52: Warning: comparison is always 1 due to limited range of data type.

I mina ögon så ser det hela rätt ut på rad 52. Om man skriver som ajg har gjort på rad 51, så
kompilerar det som det skall. Tycker att det är konstigt att jag skall behöva typa en konstant
som överstiger 127 till char om jag skall använda det för att jämföra ett char värde..

Någon som kan förklara detta ??

Bifogar källkoden (inte så lång)

/Jocke!


--- The source is with you ---
#include <stdio.h>
#include <string.h>
#include <malloc.h>

void print_usage(void);
int command_check(char *filename);

int main(int argc, char *argv[]) {
  FILE *infile, *outfile; // Filepointers to use when converting files.

  char tmp; // Delete this later.

  char *filename; // Stores the fileneme to read.
  char *outname; // Stores the filename to write.
  
  // If called without flename, display help text.
  if(argc<=1) {
    print_usage();
    printf("Ooops !\n");
    exit(1);
  }

  // copying the commandline filename to my own char pointer.
  filename = malloc(strlen(argv[1])+1*sizeof(char));
  strcpy(filename,argv[1]);

  // check to see if program was invoked with help request.
  if(command_check(filename)) {
    print_usage();
    exit(1);
  }
  
  // copying the commandline filename to my own char pointer and adding .conv.
  outname = malloc(strlen(argv[1])+strlen(".conv")+1*sizeof(char));
  strcpy(outname,argv[1]);
  strcat(outname,".conv");
  
  infile = fopen(filename,"rt");
  if(!infile) {
    printf("Could not open file %s for input\n",filename);
    exit(1);
  }

  while(infile) {
    tmp=fgetc(infile);
    if(tmp=='\0')
      break;
    if((tmp >= 21 && tmp <= 126) && tmp !=9 && tmp != 13)
      printf("%c",tmp);
    printf("%d\n",sizeof(tmp));
    //    if(tmp == (char)161 && tmp <= (char)255) && tmp != 9 && tmp != 13)
    if(tmp >= 161 && tmp <= 255) && tmp != 9 && tmp != 13)
      printf("%c",tmp);
  }
  
  // End program.
  return(0);
}


// Prints help text on the usage of the program.
void print_usage(void) {
  printf("\n\nUsage:\n");
  printf("convert {filename} to convert the file.\n");
  printf("convert --help or -h for this help\n");
  printf("The converted filename will be called : {filename}.conv\n");
  printf("\n\n");
}

/*parses the commandline to see if help is invoked.
  returns 1 if help request is found otherwise 0. */
int command_check(char *filename) {
  if(strstr(filename,"--help"))
    return(1);
  if(strstr(filename,"--HELP"))
    return(1);
  if(strstr(filename,"-h"))
    return(1);
  if(strstr(filename,"-H"))
    return(1);
  return(0);
}


--- the source has left you ---



 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 20:08 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *