- 分享
- 0
- 人气
- 0
- 主题
- 7
- 帖子
- 4707
- UID
- 82675
- 积分
- 5108
- 阅读权限
- 22
- 注册时间
- 2007-6-18
- 最后登录
- 2021-7-27
- 在线时间
- 5767 小时
|
那就是说strncpy用不着?用temp[i ]=x[i ]把各char储存就可以?我怎么没想到~现在temp[i ]已经储存所有string~可是我还是不会把它们归类成正正的数字~就好像123+456~各temp[i ]储存了每个char~但它们始终都是一个个的单数字~temp[0]=1,temp[1]=2,temp[2]=3等等~我要怎样把它们归类回变成123整数这样?我也知道我的数学运算部份都没有做變數儲存~但如果我没能把它们归类成数字的话~我就写不出~问题就这样~不懂得把它们弄成actual value~运算部分就卡住了~我也很清楚目前做的只能够把個位數做加减~就像123+456变成了3+4罢了~对不对?
yangss 发表于 2010-8-26 11:58 AM
所以以你目前的方式來做的話,首先要循环的是在判断遇到數學符号的時候才使用 strncpy 把幾個数字的字元儲存为一個字串(string)
char * strncpy ( char * destination, const char * source, size_t num );
Copy characters from stringCopies the first num characters of source to destination. If the end of the source C string (which is signaled by a null-character) is found before num characters have been copied, destination is padded with zeros until a total of num characters have been written to it.
No null-character is implicitly appended to the end of destination, so destination will only be null-terminated if the length of the C string in source is less than num.
ParametersdestinationPointer to the destination array where the content is to be copied.sourceC string to be copied.numMaximum number of characters to be copied from source.
Return Valuedestination is returned.
大多在网上找到都是做個基本從第一個字開始复制的范例,而你仔细去阅读参數的 “型态” 就無法运用,以下這個例子自己去測試後學習以後怎么去了解各函数所提供的参數運用
- #include<stdio.h>
- #include<string.h>
- int main ()
- {
- char s[17] = "This is a string.";
- char d[8] = "";
- strncpy(d, s, 7);
- printf("strncpy from char 0 to 7 will get value : (%s)\n", d);
- strncpy(d, s + 10, 7);
- printf("strncpy from char 10 to end will get : (%s)\n\n", d);
- return 0;
- }
复制代码 |
|