forked from wenjun1055/c
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f08a075
commit 6c7f9c2
Showing
13 changed files
with
234 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,3 +23,4 @@ thread4 | |
thread | ||
thread1 | ||
thread5 | ||
*.dSYM |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#include <stdio.h> | ||
#include <assert.h> | ||
|
||
char *find_char(char *source, char *chars); | ||
|
||
int main() | ||
{ | ||
char *source = "ABCDEF"; | ||
char *chars = "ESmSG"; | ||
char *result; | ||
result = find_char(source, chars); | ||
printf("%c\r\n", *result); | ||
|
||
return 0; | ||
} | ||
|
||
char *find_char(char *source, char *chars) | ||
{ | ||
assert(source != NULL); | ||
assert(chars != NULL); | ||
|
||
while (*source != '\0') { | ||
|
||
char *char_tmp = chars; | ||
|
||
while (*char_tmp != '\0') { | ||
if (*source == *char_tmp) { | ||
return source; | ||
} | ||
|
||
char_tmp++; | ||
} | ||
|
||
source++; | ||
} | ||
|
||
return "\r\0"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#include <stdio.h> | ||
#include <string.h> | ||
#include <assert.h> | ||
|
||
int del_substr(char *str, char *substr); | ||
int find_str(char *str, char *substr); | ||
|
||
int main() | ||
{ | ||
char *str = "ABCDEFGHIJK"; | ||
char *substr = "DBCD"; | ||
|
||
printf("%d", find_str(str, substr)); | ||
|
||
if (! find_str(str, substr)) { | ||
printf("not exists substr in str\r\n"); | ||
return 0; | ||
} | ||
|
||
|
||
} | ||
|
||
int find_str(char *str, char *substr) | ||
{ | ||
int counter = 0; | ||
|
||
assert(str != NULL); | ||
if (substr == NULL) { | ||
return 1; | ||
} | ||
|
||
while (*str != '\0') { | ||
char str_char = *str; | ||
char substr_char = *substr; | ||
|
||
if (str_char == substr_char) { | ||
while (1) { | ||
str_char = *++str; | ||
substr_char = *++substr; | ||
|
||
if (str_char != substr_char && substr_char != '\0') { | ||
break; | ||
} | ||
|
||
if ((str_char != substr_char && substr_char == '\0') || (str_char == substr_char && substr_char == '\0')) { | ||
return 1; | ||
} | ||
} | ||
} | ||
|
||
str++; | ||
} | ||
|
||
return 0; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
void reverse_string(char *string); | ||
|
||
int main() | ||
{ | ||
char *string = "ABCDEFG"; | ||
printf("Origion:%s", string); | ||
reverse_string(string); | ||
string = strrev(*string); | ||
printf("Change:%s", string); | ||
|
||
return 0; | ||
} | ||
|
||
void reverse_string(char *string) | ||
{ | ||
char *h = string; | ||
char *t = string; | ||
char ch; | ||
|
||
while(*t++){}; | ||
t--; | ||
t--; | ||
|
||
while(h < t) { | ||
ch = *h; | ||
*h++ = *t; | ||
*t-- = ch; | ||
} | ||
|
||
//return string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#include <stdio.h> | ||
|
||
int gcd(int m, int n); | ||
|
||
int main() | ||
{ | ||
int m,n,max; | ||
printf("Please input m and n:"); | ||
scanf("%d,%d", &m, &n); | ||
max = gcd(m, n); | ||
printf("max = %d\r\n", max); | ||
|
||
return 0; | ||
} | ||
|
||
int gcd(int m, int n) | ||
{ | ||
if (0 >= m || 0 >= n) { | ||
return 0; | ||
} | ||
|
||
int r = m % n; | ||
|
||
if (r == 0) { | ||
return n; | ||
} | ||
|
||
if (r > 0) { | ||
return gcd(n, r); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#include <stdio.h> | ||
|
||
int main() | ||
{ | ||
int max,m,n; | ||
printf("Please input m and n:"); | ||
scanf("%d,%d",&m, &n); | ||
|
||
if (0 >= m || 0 >= n) { | ||
max = 0; | ||
} | ||
|
||
max = m % n; | ||
while (max > 0) { | ||
m = n; | ||
n = max; | ||
|
||
max = m % n; | ||
} | ||
|
||
printf("%d\r\n", n); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#include <stdio.h> | ||
#include <stdarg.h> | ||
|
||
int max_list(int start, ...); | ||
|
||
int main() | ||
{ | ||
printf("max is %d\r\n", max_list(5,11,2,56,34,999,32,-1)); | ||
|
||
return 0; | ||
} | ||
|
||
int max_list(int start, ...) | ||
{ | ||
va_list var_arg; | ||
int count; | ||
int i = 0, max, current; | ||
|
||
va_start(var_arg, start); | ||
max = start; | ||
|
||
do { | ||
current = va_arg(var_arg, int); | ||
if (current > max) | ||
max = current; | ||
} while(current > 0); | ||
|
||
return max; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#include <stdio.h> | ||
#include <string.h> | ||
|
||
int main() | ||
{ | ||
char *a = "abcd"; | ||
char *b = "abcde"; | ||
|
||
if (strlen(a) > strlen(b)) { | ||
printf("1\r\n"); | ||
} else { | ||
printf("2\r\n"); | ||
} | ||
|
||
//stlen的结果是个无符号数,所以操作符>=左边的表达式也将是无符号数 | ||
//而无符号数绝不可能是负的 | ||
if (strlen(a) - strlen(b) >= 0) { | ||
printf("3\r\n"); | ||
} else { | ||
printf("4\r\n"); | ||
} | ||
} |