Write fun to delete all characters in the string referred to by STR except those with an even subscript and ASCII values. A new string formed by the remaining characters in the string is placed in the array indicated by S.

For example, if STR refers to the string ABCDEFG123456, the ASCII value of character A is odd, it should be deleted. The ASCII value of character B is even, but the subscript in the array is odd, so it should also be deleted; Character 2 has an even ASCII value and even subscripts in the array, so it should not be deleted, and so on. The last array that S refers to should be 246. 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(i%2= =0&&str[i]%2= =0)
	{
		s[j]=str[i];
		j++;
	}
	s[j]='\ 0';
}
main()
{
	char str[100],s[100];
	FILE*out;
	printf("\nplease enter string:");
	scanf("%s",str);
	fun(str,s);
	printf("\nThe result is:%s\n",s);
	out=fopen("outfile.dat"."w");
	strcpy(str,"please enter string:");
	fun(str,s);
	fprintf(out,"%s",s);
	fclose(out);
}
Copy the code

The output running window is as follows:



Other exercises this week

C programming column

Find all integers between 1 and m (including m) that can be put into array B by 7 or 11, and return the number of these numbers through n.

Find the smallest value and its subscript in a one-dimensional array element. Return the smallest value and its subscript with a parameter. The values in the array elements are assigned in the main function.

③ The following program defines an N×N two-dimensional array and assigns values in the main function. Write fun, which takes the average value of the elements around the array and returns it to r in the main function.

C programming > 7 weeks ④ Please write the function fun, its function is: STR in the string except the subscript is even, ASCII value is also even characters, all the rest of the delete; A new string formed by the remaining characters in the string is placed in the array indicated by S.

⑤ Please write a function void fun(ints,int t,intResult), which is used to find the smallest element in the array subscript, and stored in the storage location indicated by result.

The function of the given program is to determine whether a certain character in the string S is the same as the character CH. If they are the same, do nothing. If they are different, insert them in the end of the string.

Score = score = score = score = score = score = score = score = score = score = score = score

Void fun(int a[M][N],int b[N]) void fun(int a[M][N],int b[N]), void fun(int a[M][N],int b[N])

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