c - How can I convert char[] array to char* -
i want convert char[] array char* string in c programing language. here did. can't reach solution . please me. here code:
#include <stdio.h> void fnk(char *chr){ printf("%s",chr); } int main(){ char charfoo[100]; int i=50; gets(charfoo); for(int j=0;j<i;j++){ fnk((char*) charfoo[j]); } }
i think mean following
fnk( &charfoo[i]); take account better write loop following way
for( int j=0; charfoo[j]; j++ ) { fnk( &charfoo[j]); } also function gets unsafe , not supported more c standard. instead use function fgets example
fgets( charfoo, sizeof( charfoo ), stdin ); in case loop can like
for( int j=0; charfoo[j] != '\0' && charfoo[j] != '\n'; j++ ) { fnk( &charfoo[j]); } if want output 1 character in function function should defined like
void fnk(char chr){ printf("%c",chr); } and called like
fnk( charfoo[j]);
Comments
Post a Comment