C++ (Cpp) fgets Examples

C++ (Cpp) fgets - 30 examples found. These are the top rated real world C++ (Cpp) examples of fgets extracted from open source projects. You can rate examples to help us improve the quality of examples.
Example #1
0
uint32_t read_default_gateway(const char* interfaceName) {

    FILE *route = fopen("/proc/net/route", "r");
    if (route == NULL) {
        DERROR("Can't open file /proc/net/route; errno: %s", errno);
        return 0;
    }

    uint32_t result = 0;
    char buffer[256];
    fgets(buffer, sizeof(buffer), route); /* read header */
    while (fgets(buffer, sizeof(buffer), route)) {
        char *iface   = strtok(buffer, "\t");
        char *destHEX = strtok(0, "\t");
        char *gwHEX   = strtok(0, "\t");
        if (!strcmp(iface, interfaceName) && !strcmp(destHEX, "00000000")) {
            result = htonl(hex_to_uint32(gwHEX));
            break;
        }
    }

    fclose(route);

    return result;

}
Example #2
0
static void
load_module(void)
{
    FILE *fp;
    char line[8192];

    if (!module_loaded()) {
        if (verbose)
            fprintf(stderr, "Loading Flashcache Module\n");
        system("modprobe flashcache");
        if (!module_loaded()) {
            fprintf(stderr, "Could not load Flashcache Module\n");
            exit(1);
        }
    } else if (verbose)
        fprintf(stderr, "Flashcache Module already loaded\n");
    fp = fopen("/proc/flashcache_version", "ro");
    fgets(line, 8190, fp);
    if (fgets(line, 8190, fp)) {
        if (verbose)
            fprintf(stderr, "version string \"%s\"\n", line);
#ifdef COMMIT_REV
        if (!strstr(line, COMMIT_REV)) {
            fprintf(stderr, "Flashcache revision doesn't match tool revision.\n");
            exit(1);
        }
#endif
    }
    fclose(fp);
}
int main (int argc)
{
    char str01[32], str02[32];
    unsigned int  n1, n2 , result01, result02;
    int sock, port;
    port = argc;
    //sscanf(argv[1],"%d", &port);
    if(connectToServer(&sock, port)!=0) {
        sprintf(str01,"I couldn't connect to %s:%d\n",argv[1],port);
        perror(str01);
        return -1;
    }
    printf ("give me a natural number: ");
    fgets (str01,32,stdin);
    sscanf(str01,"%u",&n1);
    printf ("give me a natural number: ");
    fgets(str02,32,stdin);
    sscanf(str02,"%u",&n2);
    remoteGCD(sock, n1, n2, &result01);
    printf("gcd(%u,%u)=%u\n", n1, n2, result01);
    remoteLCM(sock,n1, n2, &result02);
    printf("lcm(%u,%u)=%u\n", n1, n2, result02);
    close(sock);
    return 0;
}
Example #4
0
int http_header(FILE* sock_file) {
    char buf[100];
    int retval = 0;

    while(fgets(buf, 99, sock_file)) {
        printf("* %s\n", buf);
        if(strncmp(buf, "GET /favicon", 12)==0 ) {
            retval = -1;
            break;
        }
        if(strncmp(buf, "GET", 3)==0) {
            retval = 0;
            break;
        }
    }

    do {
        fgets(buf, 99, sock_file);
    } while(strlen(buf) != 2);


    fprintf(sock_file,
            "HTTP/1.1 200 OK\x0d\x0a"\
            "Content-Type: text/html\x0d\x0a"\
            //	    "Transfer-Encoding: chunked\x0d\x0a"
            "\x0d\x0a");

    return retval;
}
Example #5
0
/**************  parse_keywords   ******************
*                                                  *
*  This routine reads a list of SS support file    *
*  keywords and grabs the desired value            *
*                                                  *
*  EHK  USGS  Oct 24, 2008                         *
*                                                  *
****************************************************/
int
parse_keywords(char *file, char keyword[], char *value)

{

    /***************      declaration           **********/
    int i,ii=0,index=0,scan_value;
    char ch,id[512],key[20];

    FILE *fp;


    fp = fopen(file,"r");
    if (fp == NULL)
    {
        printf("\ncan't open the input file %s!\n",file);
        exit(1);
    }

    /*************** Read Header file write label *******/

    fgets(id,512,fp);
    while (strstr(id,keyword) == NULL)
        fgets(id,512,fp);

    sscanf (id,"%s %s",key,value);

    fclose(fp);
    return(-1);

} // end of parse_keywords
Example #6
0
AlsaInfo *
computer_get_alsainfo(void)
{
    AlsaInfo *ai;
    AlsaCard *ac;
    FILE *cards;
    gchar buffer[128];

    cards = fopen("/proc/asound/cards", "r");
    if (!cards)
        return NULL;

    ai = g_new0(AlsaInfo, 1);

    while (fgets(buffer, 128, cards)) {
        gchar **tmp;

        ac = g_new0(AlsaCard, 1);

        tmp = g_strsplit(buffer, ":", 0);

        ac->friendly_name = g_strdup(tmp[1]);
        ai->cards = g_slist_append(ai->cards, ac);

        g_strfreev(tmp);
        (void)fgets(buffer, 128, cards);	/* skip next line */
    }
    fclose(cards);

    return ai;
}