Example: Assume that the input string contains only letters and # signs. Write fun, which moves all leading “#” signs to the end of the string.

For example, if the contents of the string is “# # # # b# d# c # # #”, after moving, the contents of the string should be a “# b# d# c # # # # # #”. Do not use string functions provided by C when writing functions. Do not change anything in main or the other functions; just put some statements you wrote in curly braces for fun.

The code is as follows:

#include<stdio.h>
#include<conio.h>
void fun(char*s)
{
	int i=0,n=0;
	char*p;
	p=s;
	while(*p==The '#')
	{
		n++;
		p++;
	}
	while(*p)
	{
		s[i]=*p;
		i++;
		p++;
	}
	while(n! =0)
	{
		s[i]=The '#';
		i++;
		n--;
	}
	s[i]='\ 0';
}
main()
{
	char str[81],*p;
	FILE*out;
	char test[2] [80] = {"###A###B#CD######"."###a#b#c#d###"};
	int i;
	printf("Enter a string:");
	gets(str);
	fun(str);
	printf("The string after moveing:");
	puts(str);
	out=fopen("outfile.dat"."w");
	for(i=0; i<4; i++) { fun(test[i]);fprintf(out,"%s\n",test[i]);
	}
	fclose(out);
}
Copy the code

The output running window is as follows:



Other exercises this week

C programming column

① Please write the function fun, its function is: STR in the string of even subscript characters deleted, the remainder of the string formed by the new string is placed in the array of S.

② The results of N students have been put into a linked list structure of the head node in the main function. A points to the head node of the linked list. Write a function called fun, which finds the student’s highest score and returns it.

③ Assume that the input string contains only letters and “#” signs. Write fun, which moves all leading “#” signs to the end of the string.

C programming > 11 week ④ Please write the function fun, the function is: determine whether the string is palindrome? If it returns 1, the main function prints YES, otherwise it returns 0, and the main function prints NO. Palindromes are strings that are read the same backwards and forwards.

⑤ Write a function to remove all Spaces from the string.

⑥ A student’s record consists of a student number, 5 course scores and average scores. The student number and 5 course scores are given in the main function. Write a function called fun, whose function is to find the average score of the student and put it in the recorded AVE members.

Find the number of characters STR refers to in the string, and return this value.

If there are m integers in the array, it is required to move the array elements with subscripts from 0 to t(t≤m-1) to the end of the array.

The harder you work, the luckier you get! Come on, Aoli!!