0

Hi All,

I have a program which takes a file as an input and does some processing depending upon the type of file passed.
The file types are : abc_txt, abc_ply, abc_cnvinf, abc_laneinfo etc

eg: DoWork [FileType] [File]

./DoWork txt abc_txt (or) ./DoWork cnvinf abc_cnvinf

Now I have to perform a check, like if the type and file do not match it should give an error.

That is it should check if the type and _XXX are same.

How do I proceed doing it?? I have no idea.. can anyone help??

Squirrel

2
Contributors
2
Replies
3
Views
11 Years
Discussion Span
Last Post by andor
0

I will assume that you know to work with argc and argv. It should be simple just parse the string argv[2] till the '_' char and then copy what left (from '_' till the end including '\0') to temporary string. Then just use

if (strcmp(fileExtension, tempString) != 0)
{
   // ERROR
}
-1
#include <stdio.h>
#include <string.h>

int main(int argc, char ** argv)
{
   char * c = NULL;
   
   if (argc != 3)
   {
      printf("Invalid input parametars!\n");
      return 1;
   }
   c = strrchr (argv[2], '_');
   if (c != NULL)
   {
      if (strcmp(argv[1], ++c) != 0)
      {
         printf("Error\n");
      }
      else
      {
         printf("Match\n");
      }
   }
   
   return 0;
}

Compiled with gcc

Votes + Comments
Stop Doing Homework
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.