R
ranjmis
Hi all,
Below is the code wherein I am initializing double dimentional array
inside main with string literals.
Now I want to display the strings using a function call to which I just
want to pass the array as argument with no other info like number of
strings.
Is there a way to achieve that?
Right now I have applied a workaround where I keep my last literal as
"" which acts as my end of literals.
--------------------------
#include<stdio.h>
#define NUM 20
void display(char input[][NUM])
{
char (*pc)[NUM];
int i=0;
pc=input;
for(i=0;strcmp(*pc,"")!=0;i++,pc++){
printf("%s\n",*pc);
}
}
int main()
{
char input[][NUM] = {"hi","from","ranjeet",""};
display(input);
}
----------------------
Below is the code wherein I am initializing double dimentional array
inside main with string literals.
Now I want to display the strings using a function call to which I just
want to pass the array as argument with no other info like number of
strings.
Is there a way to achieve that?
Right now I have applied a workaround where I keep my last literal as
"" which acts as my end of literals.
--------------------------
#include<stdio.h>
#define NUM 20
void display(char input[][NUM])
{
char (*pc)[NUM];
int i=0;
pc=input;
for(i=0;strcmp(*pc,"")!=0;i++,pc++){
printf("%s\n",*pc);
}
}
int main()
{
char input[][NUM] = {"hi","from","ranjeet",""};
display(input);
}
----------------------