我在用C语言编写程序时使用getchar()(在课程的这一点上还不允许使用scanf.)我想知道如果它移动到下一个,我是否每次调用它; 包括在任务操作期间.例如; 我试图从控制台读取双倍; 并确定前面是否有负号.如果是的话; 我想将变量neg指定为1(这样我可以判断最终结果是否应该返回负数)然后我想移动到下一个字符来进行实际的双重计算而不是.EX)
int x = getchar();
int neg = 0;
if(x == '-') {
neg = 1;
x = getchar(); // will this make it so the next time I use the x
} // variable it will be past the negative sign and to the
//first actual digit?
Run Code Online (Sandbox Code Playgroud) 我试图用我的一些C代码找到问题.调试器说当我尝试从指针释放mem时发生错误:
int main(int argc, char *argv[]){
char *desc = malloc(30 * sizeof(char));
if(desc == NULL)
{
fprintf(stderr, "Error - cannot allocate memory\n");
}
desc = "Debug this program.";
printf("Description: %s\n", desc);
free(desc);//break point here
int cpid = fork();
....
Run Code Online (Sandbox Code Playgroud)