该程序应该删除除字母之外的所有内容,并创建一个只有大写字母的新字符串。无法弄清楚C编程
但是,它不打印结果。
下面的代码:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char *remove_up(char input[])
{
char *new_str = (char *) malloc(strlen(input) + 1);
int i=0;
int j=0;
while (i < strlen(input))
{
if (((input[i]) >= 65 && (input[i]<=90)) || ((input[i]>=97) && (input[i]<=122)))
{
new_str[j]= toupper(input[i]);
i++;
j++;
}
else i++;
}
return new_str;
}
int main()
{
char str_1[100];
char str_2[100];
printf("Enter first word: ");
fgets(str_1, sizeof(str_1), stdin);
printf("Enter second word: ");
fgets(str_2, sizeof(str_2), stdin);
char *up_str_1 =(char *) malloc(strlen(str_1) + 1);
char *up_str_2 =(char *) malloc(strlen(str_2) + 1);
up_str_1= remove_up(str_1);
up_str_2= remove_up(str_2);
printf("%s", up_str_1);
printf("\n");
printf("%s", up_str_2);
return 0;
}
你的代码似乎已经通过'main'的定义中断了。 。 。 – ruakh 2012-02-10 23:40:19
你的程序有几个问题,但你似乎没有把整个事情放在这里。 – 2012-02-10 23:41:34
对不起,我已经发布了整个事情。除了返回0之外没有任何东西丢失;和括号。但请让我知道它是什么。 – 2012-02-10 23:42:40