小编Ade*_*war的帖子

如何在C中将数字显示为两位数?

对于C编程.如何将数字显示为00,01,02,03,而不是0,1,2,3.我只需要在数字前需要0,直到10.

我知道当你做小数时你可以做"%.2f"等但是对于整数反过来怎么样?

这是我正在使用的......**

printf("Please enter the hours: ");
    scanf ("%d",&hour);
printf("Please enter the minutes: ");
    scanf ("%d",&minute);
printf("Please enter the seconds: ");
    scanf ("%d",&second);
printf("%d : %d : %d\n", hour, minute, second);
Run Code Online (Sandbox Code Playgroud)

}

我需要将数字显示为00:00:00

??

c digit

41
推荐指数
3
解决办法
8万
查看次数

为什么我的struct只存储最后一个字符串而不是每个字符串?

所以我做了一个结构,我在一个函数内部调用它,但事情进展不顺利......

结构如下......

结构功能

struct Line {
  private:
    int lineNumber;
    char lineString[];
  public:
    bool set(int n,const char* str);
    void display() const;
};
Run Code Online (Sandbox Code Playgroud)

一切都在函数内正常工作,我存储了lineN和lineS然后将它们发送到名为... bool set(int n,const char*str)的函数中 ; (从上面)使用名为storage的结构.在第一个while循环之后,我使用了一个名为display的函数来显示lol.

设定功能

void List::set(int no){
Line storage[no];
    int i =0, x;
    while (i!=no){
        cout << "Enter line number : ";
        cin  >> lineN;
        cout << "Enter line string : ";
        cin  >> lineS;
        x = storage[i].set(lineN, lineS);
        if (x == 1){
            i++;
    }
}
i=0;
while (i!=no){
    storage[i].display();
    i++;
    }
} …
Run Code Online (Sandbox Code Playgroud)

c++ string struct function

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

标签 统计

c ×1

c++ ×1

digit ×1

function ×1

string ×1

struct ×1