int main() { char* s1 = "Iamagoodgirl"; char* s2 = "goodgirlIama"; int lenS1 = strlen(s1); int lenS2 = strlen(s2); printf("1. The length of the string is %d\n", lenS1); if(lenS1 != lenS2) { printf("2. s2 is not rotated from s1.\n"); return 0; } else { char s1s1[2*lenS1+1]; memset(s1s1, '#', 2*lenS1); memset(s1s1+2*lenS1, '\0', 1); printf("3. s1s1 is set to #\n"); printf("%s\n", s1s1); strcpy(s1s1, s1); printf("4. The s1sa sting is the same as s1:\n"); printf("%s\n", s1s1); strcat(s1s1,s2); printf("5. The s1s1 sting is %s\n", s1s1); if (isSubString(s1s1, s2)) { printf("6. The s2 is coming from the rotated s1.\n"); } else printf("7. The s2 is not from the rotated s1.\n"); } return 0; }
int main(void) { char string1[500], string2[500]; char *ptr1 = NULL; char *ptr2 = NULL; int result; int i = 0, size1 = -1, size2 = -1;//size is the size of the first and second substring printf("Please type in the first string:\n"); ptr1 = fgets(string1,100,stdin); while (*(ptr1 + i) != 0)//finds the size of the first array { i++; size1++; } printf("Please type in the second string:\n"); ptr2 = fgets(string2,100,stdin); i=0; while (*(ptr2 + i) != 0)//finds the size of the second array { i++; size2+=1; } //printf("ptr1 = %sptr2 = %s",ptr1,ptr2); result = isSubString(ptr1, ptr2, size1); if (result == 1) printf("\nThe second string is a substring of the first string\n\n"); else if (result == 0) printf("The second string is a NOT substring of the first string\n\n"); /*not a substring*/ result = isPrefix(ptr1, ptr2, size1); if (result == 1) printf("The second string is a prefix of the first string\n\n"); else if (result == 0) printf("The second string is NOT a prefix of the first string\n\n"); result = isPostFix(ptr1, ptr2, size1); if (result == 1) printf("The second string is a postfix of the first string\n\n"); else printf("The second string NOT is a postfix of the first string\n\n"); result =isInString(ptr1, ptr2, size1, size2); if (result == 1) printf("The second string is the same as the first string.\n\n"); else if (result == 0) printf("The second string is NOT the same as the first string.\n\n"); return 0; }
//目录文件计数 void countDirFile(FILE* file,struct DirEntry entryListPtr[],int dirSize,char path[],char target[],int* dirNum,int* fileNum){ int i,j; char nameptr[12]; short firstClus; for(i=0;i<dirSize;i++){ if(entryListPtr[i].DIR_Attr==0x10){ if(getVaildName(nameptr,entryListPtr[i].DIR_Name,entryListPtr[i].DIR_Attr)==1){ firstClus=entryListPtr[i].DIR_FstClus; char name[120]; strcpy(name,path); strcat(name,nameptr); if(isSubString(name,target)!=0){ if(isSubString(name,target)==-1){ (*dirNum)++; } strcat(name,"/"); int entrySize=BPB_BytsPerSec>>5; struct DirEntry entryListPtr1[entrySize]; long clusBegin=(FirstDataSectors+firstClus-2)*BPB_BytsPerSec; if(fileRead(file,entryListPtr1,clusBegin,BPB_BytsPerSec)==0){ myprint("目录读取失败"); } countDirFile(file,entryListPtr1,entrySize,name,target,dirNum,fileNum); } } } }
int main() { std::string test = "Teststringhahaha"; std::string test2 = "ddstringhahahaTest"; test = test.append(test); if ( isSubString(test, test2) ) std::cout << "This is a cyclic match" << std::endl; else std::cout << "Not a cyclic match" << std::endl; return 0; }