小编jot*_*ape的帖子

strcmp指针不能在C中工​​作

为什么这段代码不起作用.只是试图检查用户输入是否与密码相同

char *pass;

printf("Write the password: ");
scanf("%s", pass); // Because is a pointer the & is out ?


if( strcmp( pass , "acopio") == 0)
Run Code Online (Sandbox Code Playgroud)

c pointers strcmp

6
推荐指数
2
解决办法
1万
查看次数

简单的if语句在c中不起作用

谁能告诉我为什么这段代码崩溃了?这很简单,如果字符串的长度大于16,请再次询问字符串.如果我在if语句中写入control = 1,它会起作用,但如果没有它,它应该工作相同,因为那时控制的值是1,我是对的吗?泰恩斯(我正在学习)

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

int
main(void)
{
    int control = 1;
    char word[16] ;
    printf("Enter a word: ");

    while(control == 1)
    {
        scanf("%s", word);

        int len = strlen(word);
        printf("Lenght is: %d\n", len);

        if (len >= 16) 
        {
            printf("Word lenght to long, enter a new one: ");
        }

        else
        {
            control = 0;
        }

    }
    printf("This is the word: %s\n", word );

}
Run Code Online (Sandbox Code Playgroud)

c if-statement

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

数组在void函数中改变,仍在外面改变!为什么?(范围)

这是排序算法的简单实现.我的问题是.该数组numbers在main中声明并初始化.然后,我像函数中的参数一样传递它sort(是复制吗?).在sort函数内部numbers,现在被调用array(据我所知,副本)被更改(排序).那么,为什么在调用函数之后,数组numbers被改变了(这就是我想要的,买就想知道为什么??.array范围在sort,而不是main.

int main(void)
{
    int numbers[SIZE] = { 4, 15, 16, 50, 8, 23, 42, 108 };
    for (int i = 0; i < SIZE; i++)
        printf("%d ", numbers[i]);
    printf("\n");

    sort(numbers, SIZE);

    for (int i = 0; i < SIZE; i++)
        printf("%d ", numbers[i]);
    printf("\n");
    return 0;
}
void sort(int array[], int size)
{
    int swaps = 0;

    while(swaps==0)
    {
        for(int i …
Run Code Online (Sandbox Code Playgroud)

c scope function

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

在C中的函数中使用#define数字

为什么这段代码不起作用?(这不是实际代码,而是简化版本)

#include <stdio.h>
#define NUMBER 5
int function( int NUMBER );

int main (void)
{
    function( NUMBER );
    return 0;

}
int function( int NUMBER )
{
    printf("Hi %d\n", NUMBER);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c function c-preprocessor

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

标签 统计

c ×4

function ×2

c-preprocessor ×1

if-statement ×1

pointers ×1

scope ×1

strcmp ×1