c - How to iterate over a char pointer array -


how iterate on files variable in efficient way ?

should add null last value, or else ?

char *files[] =         {             "c1.txt",             "r1.txt",             "t2.c",             "d.cpp",         }; 

there several possibilities.

  • you can add null final entry, suggest yourself
  • if array comes source (like file on disk), keep counter of number of lines you're reading
  • but if array given in source, length constant , can check how many elements has (by subtracting line numbers)
  • also, size of constant array sizeof(files) / sizeof(char*).

Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -