问题描述
- 新编得程序函数调用总出错,求大神帮忙。。
-
#include
int my_str_len(void);
int print_char_array_values(void);
int char_array_reverse(void);
int main(void){
char arr[30];
int i;
char e,n,d;
while(3){
puts("Please provide a character string,don't type more than 30 elements:");
gets(arr);
/*if(arr[i]=='d' && arr[i-1]=='n' && arr[i-2]=='e')
break;*/
puts("The length of the character string is:");
my_str_len();
puts("The elements of the character string 1 are:");
print_char_array_values();
char_array_reverse();
puts("The elements of the character string 2 are:");
print_char_array_values();
}
return 0;
}int my_str_len(void){
char arr[30];
int len=0;
int i=0;
while(arr[i]!=''){
i=i+1;
len=i;
puts("%d",len);
}
return len;
}int print_char_array_values(void){
char arr[30];
int i=0;
while((arr[i]=getchar())!=''){
printf("%d",arr);
i=i+1;
}
return 0;
}int char_array_reverse(void){
char arr[30];
int i=0;
int j=0;
char t;
while(arr[i]!=''){
i=i+1;
}
i=i-1;
while(j<i){
t=arr[i];
arr[i]=arr[j];
arr[j]=t;
i=i-1;
j=j+1;
}
return 0;
}
解决方案
解决方案二:
#include<stdio.h>
#include<stdlib.h>
int my_str_len(char arr[]);
int print_char_array_values(char* arr);
int char_array_reverse(char* arr);
int main(void){
char arr[30];
int i=0;
char e,n,d;
while(i<3){
puts("Please provide a character string,don't type more than 30 elements:");
gets(arr);
/*if(arr[i]=='d' && arr[i-1]=='n' && arr[i-2]=='e')
break;*/
puts("The length of the character string is:");
printf("%d
",my_str_len(arr));
puts("The elements of the character string 1 are:");
print_char_array_values(arr);
char_array_reverse(arr);
puts("The elements of the character string 2 are:");
print_char_array_values(arr);
i++;
}
return 0;
}
int my_str_len(char* arr){
//char arr[30];
int len=0;
int i=0;
while(arr[i]!=''){
i=i+1;
len=i;
}
//puts("%d",len);
return len;
}
int print_char_array_values(char* arr){
//char arr[30];
int i=0;
while(arr[i]!=''){
printf("%c",arr[i]);
i=i+1;
}
printf("
");
return 0;
}
int char_array_reverse(char* arr){
//char arr[30];
int i=0;
int j=0;
char t;
while(arr[i]!=''){
i=i+1;
}
i=i-1;
while(j<i){
t=arr[i];
arr[i]=arr[j];
arr[j]=t;
i=i-1;
j=j+1;
}
return 0;
}
```![图片说明](http://img.ask.csdn.net/upload/201511/16/1447668133_876073.jpg)
时间: 2024-11-08 18:06:43