小编Hit*_*t's的帖子

隐藏终端上的密码输入

我想用它来掩盖我的密码*.我使用Linux GCC代码.我知道一个解决方案是使用这样的getch()功能

#include <conio.h>   
int main()
{
    char c,password[10];
    int i;
    while( (c=getch())!= '\n');{
        password[i] = c;
        printf("*");
        i++;
    }
    return 1;
}
Run Code Online (Sandbox Code Playgroud)

但问题是GCC不包含conio.h文件所以getch()对我来说没用.有没有人有办法解决吗?

c linux

53
推荐指数
4
解决办法
8万
查看次数

超时功能

我想制作一个代码,其中将要求用户名输入,但是在15秒的时间限制内.如果用户越过限制并且未能输入名称(或任何字符串),则代码将被终止并且"超时"按钮将被显示,否则名称应被保存并且"谢谢"按摩将被显示.我试过这样但是这是错误的而且没有工作.请给我一个解决方案..谢谢.

#include <stdio.h>
#include <time.h>

int timeout ( int seconds )
{
    clock_t endwait;
    endwait = clock () + seconds * CLOCKS_PER_SEC ;
    while (clock() < endwait) {}

    return  1;
}

int main ()
{
    char name[20];
    printf("Enter Username: (in 15 seconds)\n");
    printf("Time start now!!!\n");

    scanf("%s",name);
    if( timeout(5) == 1 ){
        printf("Time Out\n");
        return 0;
    }

    printf("Thnaks\n");
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c linux

7
推荐指数
1
解决办法
4万
查看次数

使用C替换文本文件中的行

我想使用C 更改包含#文本文件中的符号的行heet.

我已经尝试过这种方式,但它没有彻底运行,它只是替换字符和覆盖而不是整个字符串,就像我想要的那样.

还有其他技巧可以从文件中删除或删除整行吗?所以,我们可以轻松地取代它.

myfile.txt :( 执行前)

Joy
#Smith
Lee
Sara#
Priyanka
#Addy
Run Code Online (Sandbox Code Playgroud)

码:

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

int main() {
    FILE *pFile;
    fpos_t pos1, pos2;
    int line = 0;
    char buf[68]
    char *p;
    char temp[10] = "heet";

    pFile = fopen("myfile.txt", "r+");

    printf("changes are made in this lines:\t");    
    while (!feof(pFile)) {
        ++line;
        fgetpos(pFile, &pos1);          

        if (fgets(buf, 68, pFile) == NULL)  
            break;

        fgetpos(pFile, &pos2);

        p = strchr(buf, '#');

        if (p != NULL) {
            printf("%d, " , line); …
Run Code Online (Sandbox Code Playgroud)

c file

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

标签 统计

c ×3

linux ×2

file ×1