Format the input and output files
# include "stdafx. H "<br/> # include <stdlib. h> <br/> # include "string. H "<br/> # include" stdio. H "<br/> int main () <br/>{< br/> file * FP; <br/> int number [3]; <br/> int score [3]; <br/> int I = 0; <br/> int rece_number = 0; <br/> If (FP = fopen ("test.txt", "R") = NULL) <br/>{< br/> fprintf (stderr, "Error opening file! /N "); <br/>}< br/> for (I = 0; I <3; I ++) <br/>{< br/> fscanf (FP, "% d", & number [I], & score [I]); // enter a space for the student ID and score <br/>}< br/> printf ("Please input number:/N"); <br/> scanf ("% d ", & rece_number); <br/> for (I = 0; I <3; I ++) <br/> {<br/> If (rece_number = number [I]) <br/> break; <br/>}< br/> printf ("the number's score is % d/N", score [I]); <br/> fclose (FP ); <br/> return 0; <br/>}< br/>
count the longest repeated string in a string
# Include "stdafx. H "<br/> # include" string. H "<br/> # include" malloc. H "</P> <p> int main () <br/>{< br/> int I, J, K, T; <br/> int max = 0; <br/> char * P = NULL; <br/> char STR [42] = "2xtuaojy5678zuaojy908puaojy#uaojy356"; <br/> char temp [8]; <br/> char result [8]; <br/> memset (result, 0, 8); <br/> P = STR; <br/> for (I = 0; I <42; I ++) <br/>{< br/> for (j = I + 1; j <42; j ++) <br/>{< br/> If (* (p + I) = * (p + J) <br/>{< br/> T = I; <br/> K = 0; <br/> memset (temp,); <br/> // if the same first character is found, start the comparison until there are no identical characters, record the current string to see if it is the longest <br/> while (* (p + T) = * (p + J )) <br/> {<br/> temp [k] = * (p + T); // compare subsequent characters continuously <br/> T ++; <br/> J ++; <br/> K ++; <br/>}< br/> If (k> MAX) // assign the longest string to result <br/>{< br/> max = strlen (temp); <br/> strcpy (result, temp ); <br/>}</P> <p >}< br/> // print the result above the longest string is "zuaojy" <br/> printf ("the longest repeated string is % s, length: % d/N ", result, max); <br/> return 0; <br/>}
Recursively calculate the number of identical characters in a string
Int count_times (char CH, const char * Str) <br/>{< br/> int COUNT = 0; <br/> If (* STR = '/0 ') <br/>{< br/> COUNT = 0; <br/>}< br/> else <br/>{< br/> If (* Str) = CH) <br/>{< br/> COUNT = 1 + count_times (CH, STR + 1 ); <br/>}< br/> else <br/> {<br/> COUNT = count_times (CH, STR + 1 ); <br/>}< br/> return count; <br/>}