In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces "C language programming example topic analysis". In daily operation, I believe that many people have doubts about c language programming example problem analysis. The editor has consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts of "C language programming example problem analysis". Next, please follow the editor to study!
1. Topic description
Provides that the input string contains only letters and * signs, please write the function fun, its function is: the string at the front of the consecutive * sign not more than n; if more than n, then delete the extra * sign: if less than or equal to n, then do nothing, the string in the middle and tail of the * sign is not deleted.
For example, the contents of the string are as follows: * AbeliBCcompressed DEFGONFGOBSTRAN. If the value of n is 4, the content of the string should be * ACEBCDEFDEFGRANGROWTH. If the value of n is 8, the content of the string will still be: * the value of AANGBCDEFGRANGRON is entered in the main function. When writing a function, you must not use the string function provided by C language.
Note: some of the source programs are stored in the file prog1.c
Do not change anything in the main function main and other functions, just fill in some of the statements you have written in the curly braces of the function fun.
2. Some programs:
# include
Void fun (char * a, int n)
{
/ * the following code is for reference only * /
Int iMagn0.jjjjjjj.kumb0.
While (a [k] = ='*') k characters; / * k is the count of * characters * /
If (k > n)
{
IAccording to the jackpot
/ * the following is completed to move the characters from the subscript k to the end of the string forward to kmurn positions * /
}
}
Main ()
{char s [81]; int nscape void NONO ()
Printf ("Enter a string:\ n"); gets (s)
Printf ("Enter n:"); scanf ("% d", & n)
Fun (sforme n)
Printf ("The string after deleted:\ n"); puts (s)
NONO ()
Getchar ()
}
Void NONO ()
{/ * this function is used to open files, input data, call functions, output data, and close files. , /
FILE * in, * out
Int I, n; char s [81]
In = fopen ("C:\\ WEXAM\\ 000000000000\\ in.dat", "r")
Out = fopen ("C:\\ WEXAM\\ 000000000000\\ out.dat", "w")
For (I = 0; I)
< 10 ; i++) { fscanf(in, "%s", s) ; fscanf(in, "%d", &n) ; fun(s,n) ; fprintf(out, "%s\n", s) ; } fclose(in) ; fclose(out) ; } 3、参考答案: 本題的考核点是删除字符串中字符的算法 解题思路:先统计串前连续的中号个数,与指定的个数进行判断,若小于等于指定的数,什么也不做,若大于指定的数则将多余的*号删除。 本评析仅供参。 void fun( char *a, int n ) { /* 以下代码仅供参考 */ int i=0,j,k=0; while(a[k]=='*') k++; /* k为统计*字符个数 */ if(k>n)
{
IAccording to the jackpot
/ * the following is completed to move the characters from the subscript k to the end of the string forward to kmurn positions * /
Strcpy (& a [0], & a [k-n])
}
}
At this point, the study of "C language programming example topic analysis" is over. I hope to be able to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
You can get a lot of information from http://docs.seleniumhq.org/.
© 2024 shulou.com SLNews company. All rights reserved.