c - Can anyone help me with this code? -
i think logic correct it's not printing anything. code eliminate vowel string , display it.
#include<stdio.h> #include<conio.h> void main() { char *str="shivank"; int i,len; char *q; clrscr(); len=strlen(str); for(i=0;i<=len;i++) { if((*str=='a')||(*str=='e')||(*str=='i')||(*str=='o')||(*str=='u')) str++; else if(*str=='\0') break; else { *q=*str; str++; q++; } } *q='\0'; puts(q); getch(); }
if understand correctly, want transform "shivank"
"shvnk"
, , store in seperate string print later.
you have allocate memory somewhere. working pointers won't work - @ best, change str
point different beginning of string: "hivank"
, "ivank"
, "vank"
etc.. possible using pointer arithmetics, that's it.
i recommend use char
arrays instead of using string constants:
char str[] = "shivank"; char modified_str[10]; // enough memory store modified string
the advantage of using arrays can modify them example:
modified_str[0] = str[0];
(this example copies first letter of str
first letter of modified_str
)
then read characters of str
string 1 one, , copy non-vowels modified_str
. don't forget end modified_str
'\0'.
Comments
Post a Comment