I am unclear on how to get string functions to talk to the main program. What I am trying to do is take a sentence, then return it with all blanks removed. Has to be done within a function.
Where am I going wrong?
See code below.
#include <stdio.h>
#include <string.h>
char *noblank(char *, int);
void main ()
{
char sentence[80];
int i, length;
char *dest;
printf("enter a sentence> \n");
gets(sentence);
length = strlen(sentence);
printf("length is %d\n", length);
dest =*noblank(&sentence, length);
printf("%s\n", dest);
}
char *noblank(char *sentence, int length)
{
int i;
int newlen = length+1;
char dest[newlen];
for (i = 0; i != ' ' && i != '\n' && i < newlen; ++i)
dest[i++] = getchar();
dest[i] = '\0';
return (dest);
}



LinkBack URL
About LinkBacks


