Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

指针10.c #6

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion 1基本技能开发技巧/10.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ main()
****************************************/
/*
#include <stdio.h>
int bin_dec(int x,int n) //将而进制转换成十进制
int bin_dec(int x,int n) //将二进制转换成十进制
{
if(n==0)
return 1;
Expand Down
53 changes: 38 additions & 15 deletions 2指针开发技巧/10.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/****************************************
/****************************************
技巧01:使用指针实现整数排序
****************************************/
/*
Expand Down Expand Up @@ -170,7 +170,7 @@ int main(int argc, char *argv[])
}
*/
/****************************************
技巧07:使用指针实现字符串复制(复制函数没有写成功)
技巧07:使用指针实现字符串复制(原写法会导致段错误)
****************************************/
/*
#include <stdio.h>
Expand All @@ -187,17 +187,18 @@ copy(char *s,char *q)
}
main()
{
char *str,*p;
str="hello world!";
//char *str,*p;
char *str = "hello world!";
char p[100];
//str="hello world!";
copy(str,p);
printf ("%s",p);
return 0;
}
*/
/****************************************
技巧08:使用指针实现字符串的连接(段错误,未成功)
技巧08:使用指针实现字符串的连接(和上面错误原因相同)
****************************************/
/*
#include <stdio.h>
connect(char *s,char *t,char *q)
{
Expand All @@ -218,7 +219,9 @@ connect(char *s,char *t,char *q)
}
int main(int argc, char *argv[])
{
char *str,*t,*p;
// char *str,*t,*p;
char *str,*t;
char p[100];
str="one world";
t="one dream";
printf ("the first string is:%s\n",str);
Expand All @@ -228,9 +231,9 @@ int main(int argc, char *argv[])
printf ("%s",p);
return 0;
}
*/

/****************************************
技巧09:使用指针实现字符串插入(未成功)
技巧09:使用指针实现字符串插入
****************************************/
/*
#include <stdio.h>
Expand All @@ -256,17 +259,37 @@ insert(char *s,char *q,int n)
}
str[i+1]='\0';
return str;
}*/
/*修改 不可返回局部变量,声明函数指针,源程序存在段错误
char *insert(char*s, char *p, int n, char *t)
{
int i;

for(i=0; *s!='\0'; i++){
if(i = n-1){
while(*p='\0'){
t[i] = *p;
i++;
p++;
}
}
t[i] = *s;
s++;
}
t[i] = '\0';
return t;
}
int main(int argc, char *argv[])
{
char *strin,*str;
int i;
str="hello world!";
strin ="big";
char *s,*p;
int n;
char m[80];
s ="hello world!";
p ="big";
printf ("please input the position you want to insert:");
scanf("%d",&i);
str=insert(str,strin,i);
printf ("%s\n",str);
s=insert(s, p, n, m);
printf ("%s\n",s);
return 0;
}
*/
Expand Down
38 changes: 36 additions & 2 deletions 6常用的30个算法及应用/10.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/****************************************
技巧01:冒泡排序
/****************************************
技巧01:冒泡排序
****************************************/
/*
#include <stdio.h>
Expand All @@ -24,6 +24,40 @@ int main(int argc, char *argv[])
}
*/
/****************************************
技巧01:冒泡排序 (优化)
****************************************/
/*
#include<stdio.h>
void swap(int *a; int *b)
{
int t;
t = *a;
*a = *b;
*b = t;
}
void bubble_sort(int arr[]; int len){
int i,j;
for(i=0; i < len - 1; i++){
for(j=0; j < len-1-i; i++){
if(arr[j] > arr[j+1])
swap(&arr[j], &arr[j + 1]);
}
}
}
int main(int argc, char *argv[])
{
int i,a[10];
for(i=0; i<10; i++){
scanf("%d",&a[i]);
}
bubble_sort(a, 10);
for(i=0; i<10; i++){
printf("%d\n", a[i]);
}
return 0;
}
*/
/****************************************
技巧02:选择排序
****************************************/
/*
Expand Down
2 changes: 1 addition & 1 deletion 7C语言注意事项/基础的技术细节
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ goto语句使用时有以下三点要注意:
要从被调函数返回一个函数值,被调函数中必须包含return语句。当函数执行到return
语句时,按照return关键字后面的要求返回相应的内容给主调函数。即使被调函数后面
还有语句也不再执行。因此,return语句也可以看作是函数执行的结束语句。如果不需
要从被调函数中返回值,则可以不使用return语句。
要从被调函数中返回值,则可以不使用return语句,返回值不可返回局部变量
============================================================================