how to split command line arguments equally in C -


i writing c program using command line arguments. when ever give string in command line space splits sub files ,

for ex- sample output

$ ./cmdline 4646 313 256 96664  commandline args count=5 exe name=./cmdline split_part1=4646 split_part2=313 split_part3=256 split_part4=96664 

i want same output without giving space in between string. how do,each sub part should split equal number of strings . please help.

#include <stdio.h> int main (int argc, char *argv[] ) {   int i=0;   printf("\n commandline args count=%d", argc);   printf("\n exe name=%s", argv[0]);   (i=1; i< argc; i++)   {     printf("\n");     printf("\n split_part%d=%s", i, argv[i]);   }    printf("\n");    return 0;   } 

following comments, simple algorithm achieve want looks like

(for fixed token size of 5, can modified per requirement later)

  1. check if argc ==2.
  2. calculate string length of argv[1], store it.
  3. take variable used index.
  4. write loop breaking condition index < string_length , increment condition index +=5.
  5. use printf() (used illustration, can add storing part also) like

    printf("%5s\n" &(argv[i][index])); 

Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -