我不明白指针在for循环中的作用.什么是*p在下面的循环呢?
char str[128] = "Some Text";
char *p;
for (p = str; *p /*what does this mean?*/; p++)
{
// Code
}
Run Code Online (Sandbox Code Playgroud)
我确实了解其余的,但为什么不*p喜欢p > 3或类似的东西?
为什么一个人?
为什么这样写?
尝试学习 C,所以我想反转字符串中的每个单词。“Hello World”到“olleH dlroW” 这是我目前所拥有的。
int main()
{
char str[100];
int i;
printf("Enter string:");
fgets(str,sizeof(str),stdin);
for (i = 0; i <= strlen(str); i++)
{
if (str[i] == ' ')
{
// Here the space and how should I switch words now?
}
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我应该做这样的事情:
温度 = str[i]; j = str[i-1];
然后换地方?str[i]=j; j=温度; 我被困在这里!
我正在学习C,我的老师给了我一个任务,但我被困住了.在数组中有10个正数,我需要找到具有最高总和的3个连续数字.我在网上找到了这个解决方案,但是如何找到3个连续数字并求它们呢?我该怎么做呢?我应该在数组中查找最大数字并从那里开始吗?我发现的代码在我到目前为止做得更好.
该数组具有:{1,2,3,2,0,5,1,6,0,1},那么3个数字的最大总和将是{ 1,2,3,2,0,5,1,6,0,1},因为它给出了12
#define N_ELEMENTS 10
int main(int argc, const char * argv[]) {
int a[N_ELEMENTS] = {1, 2, 3, 2, 0, 5, 1, 6, 0, 1};
int i = 0;
while(a[i] < 0 && i<N_ELEMENTS) {
i++;
}
if (a[i] < 0) {
printf ("DEBUG: array with only negative numbers. Print the smallest negative number as the sum and we are done.\n");
}
int sum_p=0, sum_n = 0;
int largest_sum = 0;
while (i<N_ELEMENTS) {
if (a[i] > …Run Code Online (Sandbox Code Playgroud)