2013-03-11 91 views
2

我需要你们的帮助,我们卡在K & R练习1-13。它的功能!我通过几乎所有的1章,但坚持功能。我无法理解如何使用函数。那么我知道如何做简单的功能,但当我来到更复杂的一个我卡在它!不知道如何传递数值,功率函数的例子有点难以理解。但是无论如何,如果您可以完成它,我需要您在练习1 - 13的帮助,以便我能够阅读代码并了解如何使用函数。
这里行使它的自我:
写一个程序,它的输入转换为小写,使用函数如果c不是字母较低(三)巫返回对应c和c的小写值,如果它是一个字母C语言编程K&R练习1-13

如果你知道一些链接或任何女巫有一些有关如何处理更困难的功能(不喜欢将字符串传递给主,但算术一)的有用信息,请你把它们链接起来。

而且这不是k &的R 2版

+1

什么是您的谷歌查询?我怀疑你的研究技能不足。确保你使用的是最新的书; IT行业变化非常迅速,任何使用史前技术的人都会落后。 – Sebivor 2013-03-11 02:50:53

+0

@modifiable lvalue我会问在这里,如果我会在谷歌找到任何有用的信息。 MB我的研究技能有点糟糕。 – AlexGreat 2013-03-11 02:53:20

+2

*“...如果它可能为您完成它..”* * * *你*至少***尝试***“完成它”并返回,代码在手,与问题有关您在此过程中遇到的问题。 – WhozCraig 2013-03-11 02:54:01

回答

0

如果已读ķ& R,while循环,其中一个简单的getchar()/的putchar()组合的第1章。是用来获取和显示字符,我相信你会发现这个程序很熟悉。

#include<stdio.h> 

int main() 
{ 

int ch; 
    while((ch = getchar()) != EOF) 
    { 
     if((ch>=65)&&(ch<=122)) 
     { 
      if((ch>=97)&&(ch<=122)) 
       ch=ch-32; 
      else if((ch>=65)&&(ch<=90)) 
      ch=ch+32; 
     } 
     putchar(ch); 
    } 
return 0; 
} 
+0

我的K&R是不同的。我使用俄语版的K&R。书中90%的例子完全不同 – AlexGreat 2013-03-11 03:43:05

1
/* 
* A function that takes a charachter by value . It checks the ASCII value of the charchter 
* . It manipulates the ASCII values only when the passed charachter is upper case . 
* For detail of ASCII values see here -> http://www.asciitable.com/ 
*/ 
char lower(char ch){ 

    if(ch >= 65 && ch <=90) 
    { ch=ch+32; 
    } 
    return ch; 


} 
int main(int argc, char** argv) { 
    char str[50]; 
    int i,l; 
    printf("Enter the string to covert "); 
    scanf("%s",str); 
    /* 
    Get the length of the string that the user inputs 
    */ 
    l=strlen(str); 

    /* 
    * Loop over every characters in the string . Send it to a function called 
    * lower . The function takes each character by value . 
    */ 
    for(i=0;i<l;i++) 
    str[i]=lower(str[i]); 

    /* 
    * Print the new string 
    */ 

    printf("The changes string is %s",str); 
    return 0; 
} 
+0

@AlexGreat。如果你自己第一次尝试代码,会更好。这里的人们在计算器上已经准备好帮助那些首先帮助自己的人。您可以发布您不明白的片段。不过,我知道你可能正在努力,所以我发布了一个小解决方案。有多种方法可以解决这个问题。这只是一个。可能不是最好的。可能不是最优化的一个。希望它能让你开始。 – rockstar 2013-03-11 03:15:30

+0

太棒了!这是我正在寻找的。非常感谢你 。我实际上做了几乎相同的事情,同时试图做我的自我,但有很多的错误。再次感谢您 – AlexGreat 2013-03-11 03:41:49