小编ᴜsᴇ*_*sᴇʀ的帖子

逻辑AND运算符

我对逻辑运算符很困惑.我有这两行代码.这里numj都是int.我有一种情况,两个条件都满足,但我不知道为什么它不打印的价值j.任何人都可以指出错误吗?提前致谢.

if(k==1 && num%j==0)
    printf("%d",j);
Run Code Online (Sandbox Code Playgroud)

c boolean-logic boolean-operations

1
推荐指数
1
解决办法
294
查看次数

bash计算器代码的说明

有人能解释一下这个bash代码吗?

read text && echo $text | bc -l
Run Code Online (Sandbox Code Playgroud)

谢谢!

linux bash shell calculator

1
推荐指数
1
解决办法
176
查看次数

哪一个选择:退出还是退货?

我知道returnexit()(链接)之间的区别,但我不知道在何时何地选择一个而不是另一个.例如,根据这个答案,我理解这return是一个更好的选择,但从另一个我理解相反.

一个例子:在这个代码中(来自这个问题)是否优先使用exit()return

int read_file (char *filename, int **vet)
{
    FILE *fin;

    if ( !(fin = fopen(filename, "r")) )
    {
        perror(filename);
        return -1;
    }

    * vet = malloc (10 * sizeof(int));
    if ( *vet == NULL )
    {
        perror("Memory allocation error.\n");
        return -2;   
    }

    /* ... */

    return fclose(fin);
}

int main ()
{
    char filename[100];
    int *vet;

    if ( read_file(filename, &vet) ) …
Run Code Online (Sandbox Code Playgroud)

c return return-value exit

1
推荐指数
1
解决办法
230
查看次数

将函数字符串返回main

我想从函数(在示例funzione中)返回一个字符串到main.这该怎么做?谢谢!

#include <stdio.h>
#include <string.h>

#define SIZE (10)

/* TODO*/ funzione (void)
{
    char stringFUNC[SIZE];

    strcpy (stringFUNC, "Example");

    return /* TODO*/;
}

int main()
{
    char stringMAIN[SIZE];

    /* TODO*/

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

[已编辑]对于那些需要它的人来说,以前代码的完整版本(但没有stringMAIN)是:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define SIZE (10)

char *funzione (void)
{
    char *stringa = malloc(SIZE);
    strcpy (stringa, "Example");

    return stringa;
} 

int main()
{
    char *ptr = funzione();

    printf ("%s\n", ptr);

    free (ptr);

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c string program-entry-point function

-1
推荐指数
1
解决办法
2308
查看次数

询问用户他们的姓氏和名字,并输入一个电子邮件作为输出

#include <stdio.h>

int main(){

    char last[20];
    char first[20];

    printf("Please enter your last name:");
    scanf("%s",last);
    printf("\nPlease enter your first name:");
    scanf("%s",first);
    printf("Here your email address\n",last,first,@student.com); //last first@student.com

}
Run Code Online (Sandbox Code Playgroud)

我希望用户写下他们的名字,我会自动输出他们的电子邮件.

c printf

-2
推荐指数
1
解决办法
2232
查看次数