0
我应该建立一个程序,需要argv [1],并根据它将字符转换为小写或大写。但是我卡住cuz C不能比较指针一个字符串。关于如何比较一个指针和一个字符串的任何想法,我不想按字符比较它们。 下面是代码建立一个字符转换器程序与argv []
#include <stdio.h>
#include <ctype.h>
#include <string.h>
int main (int argc,char *argv[])
{
char c;
if(argc!=2)
printf("Wrong use of program \n");
printf("The Format is Lower or Upper \n");
return -1;
if ((strcmp(argv[1],"Lower"))==0)
{
while((c=getchar())!=EOF)
{
printf("-");
putchar(tolower(c));
printf("\n");
}
}
if ((strcmp(argv[1],"Upper"))==0)
{
while((c=getchar())!=EOF)
{
printf("-");
putchar(toupper(c));
printf("\n");
}
}
if ((strcmp(argv[1],"Lower"))!=0 && ((strcmp(argv[1],"Upper"))!=0))
{
printf("Wrong use of program \n");
printf("The Format is Lower or Upper \n");
return -1;
}
return 0;
}
虽然仍然没有工作。 – Lind 2013-03-16 14:12:34
它现在适用于我。 – suspectus 2013-03-16 14:21:36
我没有看到你的下一个edit.Thanks人。 – Lind 2013-03-16 15:30:37