<分区>
在我下面的代码中:
#include <stdio.h>
#include <stdlib.h>
void build(char *input){
// how do I get the first string "one" here from the *input pointer? and dissect the string - 'one' so that I can get each character separately
}
int main() {
const char *strings[] = { "one", "two", "three" };
printf("1st string is %s\n", strings[0]);
build(strings);
return 0;
}
我的这个程序的目标是在我的构建函数中获取每个字符串,比如“一个”,并分离出每个字符 - 'o'、'n'、'e',然后找到一个数字,它是总和111('o') + 110('n') + 101 ('e') = 322 的 ASCII 码。(每个字符串可能有不同的长度)
After compiling others answer I came up with this: Please let me know if this ok?
Possible Answer:
#include <stdio.h>
#include <stdlib.h>
void build(char *input) {
int i = 0;
int a=0
while (*input != '\0') {
printf("character is %c\n", *input);
a=a+*input;
input++;
}
printf("sum of ascii value of each character is %d\n",a);
printf("------\n");
}
int main() {
const char *strings[] = { "one", "two", "three" };
int i = 0;
for (i = 0; i < sizeof strings / sizeof *strings; i++)
build(strings[i]);
return 0;
}