Write a function that removes all whitespace from a string
Error analysis:
This is because when the character constant is a space character, you cannot enter only two single quotes, you must also enter a space between the two single quotes; Otherwise, an error will be reported when compiling, prompting null characters, as shown in the figure:
After consulting materials, it is not allowed to put nothing between two single quotation marks. After modification, it is shown in the following figure:
Code:
#include <stdio.h>
#include <ctype.h>
#include <conio.h>
#include <stdlib.h>
void fun (char *str)
{
int i=0;
char *p=str;
while(*p){
if(*p!=' '){ //Del Space key
str[i++]=*p;
}
p++;
}
str[i]='\0'; //add Terminator
}
main()
{
char str[81];
char Msg[]="Input a string:";
int n;
FILE *out;
printf(Msg);
gets(str);
puts(str);
fun(str);
printf("*** str: %s\n",str);
/******************************/
out=fopen("out.dat","w");
fun(Msg);
fprintf(out,"%s",Msg);
fclose(out);
/******************************/
}
Read More:
- error C2137: empty character constant
- error C2057: expected constant expression (Can the size of an array in C language be defined when the program is running?)
- C language string processing error warning, c4996, sprintf, predicted, c4996, strcpy, c4996, strcat
- Explain stdin, stdout, stderr in C language
- The function and usage of argc and argv in C language
- Error of reading character c + +
- On the coercion of C language
- C language error: stray ‘\ 240’ in program|
- C language write() function analysis: write failed bad address
- Solution to the segmentation fault of single chain table in C language
- The use of Chinese characters in Qt and the solution to the “error C2001: newline in constant” problem
- The language of C__ FILE__ 、__ LINE__ And line
- The C language qsort() function reports an error for overflow of – 2147483648 and 2147483648
- R language – error analysis – error in Call.graphics (C_ palette2, .Call(C_ palette2, NULL)) : invalid graphics state
- Error c2059: syntax error: constant solution
- C – error: converting to execution character set:Illegal byte sequence
- Solution to error [error] LD returned 1 exit status in C language
- C language — to solve the problem of program flashback when programming (in VS)
- C language problem: 0xc0000005: access conflict occurred when writing to location 0xffffcc.
- C language error: expected declaration or statement at end of input