Search
 
SCRIPT & CODE EXAMPLE
 

C

c read csv

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

const char* getfield(char* line, int num)
{
    const char* tok;
    for (tok = strtok(line, ";");
            tok && *tok;
            tok = strtok(NULL, ";
"))
    {
        if (!--num)
            return tok;
    }
    return NULL;
}

int main()
{
    FILE* stream = fopen("input", "r");

    char line[1024];
    while (fgets(line, 1024, stream))
    {
        char* tmp = strdup(line);
        printf("Field 3 would be %s
", getfield(tmp, 3));
        // NOTE strtok clobbers tmp
        free(tmp);
    }
}
Comment

PREVIOUS NEXT
Code Example
C :: c print char 
C :: Graphics in C Draw A Line 
C :: how to make a linked list in c 
C :: mongodb update 
C :: downgrade chrome to previous stable version in linux 
C :: c if else 
C :: C Passing string to a Function 
C :: bash while loop n times 
C :: C Program to Find Largest and Smallest Number among N 
C :: Convert mpg / mp4 to gif with ffmpeg 
C :: C scanf() to read a string 
C :: binary tree in c search 
C :: number of hours, minutes, and seconds given the number of seconds. 
C :: strings in c 
C :: bootsrap textbox 
C :: C (ANSI) 
C :: DrawText() raylib 
C :: read file c 
C :: sh: tailwindcss: command not found 
C :: convert char number to int in c 
C :: mysql yyyymm format 
C :: how to input till end of line in c 
C :: c add char to char array 
C :: c command line arguments parser 
C :: logical operators in c 
C :: C How to define a union? 
C :: With which of the following can you run code without provisioning or managing servers and pay only for the compute time consumed (there is no charge when the code is not running)? 
C :: cocktail sort in c 
C :: google business customer care number india 24/7 
C :: konami code hdl 
ADD CONTENT
Topic
Content
Source link
Name
2+6 =