#include<stdio.h>
#include<string.h>
int main(){
char array[]="Arijit Saha Student";
spaceremover(array);
getch();
return 1;
}
int spaceremover(char a[]){
int i;
// printf("L=%d",strlen(a));
char final[strlen(a)+1];
int count=0;
for(i=0;i<strlen(a);i++)
{
if(a[i]!=' ')
final[count]=a[i];
count++;
}
final[count]='\0';
int j=0;
for(j=0;j<strlen(final);j++)
printf("%c",final[j]);
// printf("\n%s",final);
return 1;
}
With this example code the output is Arijit.Saha, but my desired output is ArijitSahaStudent.
Why am I getting the wrong output?
Where the . is coming from?
countis being incremented no matter what. You should put curly braces aroundfinal[count]=a[i];andcount++socountonly increments when a letter is added to the array. Currently, when it gets to a space, nothing is added to thefinalarray at that positionchar final[strlen(a)+1];: is this legal in C?