Example: Write fun, which removes odd ASCII characters from the string indicated by STR and places the remaining characters in the string into a new string in the array indicated by S.

For example, if STR refers to asdf in the string, s refers to DF in the array. 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<conio.h>
#include<stdio.h>
#include<string.h>
void fun(char*str,char s[])
{
	int i,j=0,n;
	n=strlen(str);
	for(i=0; i<n; i++)if(str[i]%2= =0)
	{
		s[j]=str[i];
		j++;
	}
	s[j]='\ 0';
}
main()
{
	char str[100],s[100],m[]="Please enter string:";
	FILE*out;
	printf(m);
	scanf("%s",str);
	fun(str,s);
	printf("\nThe result is:%s\n",s);
	out=fopen("ooutfile.dat"."w");
	fun(m,s);
	fprintf(out,"%s",s);
	fclose(out);
}
Copy the code

The output running window is as follows:



Other exercises this week

C programming column

Fun: delete the characters with even subscript and odd ASCII value in STR, and place the new string formed by the remaining characters in STR in the array indicated by S.

Find the square root of the sum of all natural numbers within m (excluding m) divisible by 3 and 7, and return it as a function value.

C programming > 10 weeks ③ Please write the function fun, its function is: STR refers to the string of odd ASCII characters deleted, the remaining characters in the string to form a new string in the array referred to by S.

C programming > 10 weeks ④ Please write the function fun, its function is: two two-digit positive integer x, y into an integer in z. This is done by placing the tens and ones places of x in the hundreds and ones places of Z, and the tens and ones places of y in the tens and thousands places of Z.

C programming > 10 weeks ⑤ student record by student number and result composition, M student data has been put into the structure array STu in the main function, please write function fun, its function is: function return specified student number data, specified student number input in the main function.

Write the function fun, which calculates and outputs the following polynomial: Fn =1+1/1! + 1/2! + a third! + a quarter! +… +1/m!

Count the number of words in a string and return them as a function value. A string is entered in the main function, specifying that all words are lowercase letters separated by Spaces, with no Spaces at the beginning and end of the line.

C language programming > 10 weeks today, please write a function fun, its function is: the two two positive integers x, y merged into an integer in the z. This is done by placing the tens and ones places of x in the tens and thousands places of Z, and the tens and ones places of y in the hundreds and ones places of Z.

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