convert python code to c online 1

convert python code to c online

#Importting csv module
import csv
#csv file name
filename= "aapi.csv"
# intiliaze titles and rows
fields =0
rows = 0
# reading csv file
with open(filename,'r') as csvfile:
    # extract each data row one by one 
    csvreader=csv.reader(csvfile)
    rows.append(rows)
    # get total no of rwos
    print("Total no of rows:%d%(csvreader.line_num)")
    # print fields name
    print('Field names are:' + ', '.join(field for field in fields))
    # print first 5 rows
    print('\n First 5 rows are:\n')
    for row in rows[:5]:
    # parsing each column of rows
        for col in row:
            print("%10s"%col),
        print('\n')

Here is what the above code is Doing:
1. We first import the csv module.
2. We then open the CSV file using the open() function.
3. We use the csv.reader() function to read the file, which returns an iterable reader object.
4. We then loop over the reader object and retrieve each row of the data.
5. We print the number of rows and the field names.
6. We print the first five rows of data.

Similar Posts