Reading CSV File Using C Program
June 2, 2008
Since I'm on an integration project, I'm mostly dealing with transferring of data from two or more systems whether it's from the legacy system or newly implemented system. Most of the type of data movement is sending CSV files to and from the different system. Here is a simple tutorial on how to read CSV. The CSV file contains the following:
-
1111,1414,1000
-
1112,1010, 1001
-
1113,1112,1002
The fields are Item Number, Class Number and Supplier Number.
The example below is the simple code of reading CSV file in C.
-
#include <stdio.h>
-
#include <stdlib.h>
-
#include <string.h>
-
-
int main(int argc, char* argv[])
-
{
-
if (argc <2)
-
{
-
fprintf(stderr,"Usage: %s csv_file\n",argv[0]);
-
return(1);
-
}
-
-
FILE *f = fopen(argv[1], "rt");
-
char Line[256];
-
unsigned int AllocSize = 0, Size = 0, n;
-
char *L_text;
-
-
while(fgets(Line, sizeof(Line), f))
-
{
-
-
printf("Item = %s \n",strtok(Line, ", "));
-
printf("Class = %s \n",strtok(NULL, ", "));
-
printf("Supplier = %s \n",strtok(NULL, ", "));
-
-
}
-
return(0);
-
}
How to display newline in Excel?
January 12, 2008
The commonly used to display newline in Visual Basic is using VbCrLF. But the problem is you will see a small rectangle at the end of the line.

-
Dim strFirstLine As String
-
Dim strSecondLine As String
-
-
strFirstLine = "This is the first line"
-
strSecondLine = "This is second line"
-
-
Worksheets("Sheet1").Range("b4").Value = _
-
strFirstLine & vbCrLf & strSecondLine
To solve this problem, you will need to change the code from VbCrLF to VbLf.
-
Dim strFirstLine As String
-
Dim strSecondLine As String
-
-
strFirstLine = "This is the first line"
-
strSecondLine = "This is second line"
-
-
Worksheets("Sheet1").Range("b4").Value = _
-
strFirstLine & vbLf & strSecondLine

Pro *C Programming Do’s and Don’t
November 18, 2007
- Use one array per action such as inserting, updated and deleting records.
- Always increment the array counter every time you add new records.
- Always resize array every time you add new records.
- Always reset the array counter after the bulk update, insert and delete.
- Inserting or updating records should comes last if the value of column in comes from a separate logic such as calculation, sequence retrieval.
Software Best Practices Conference
September 23, 2007
I want to share ideas from Youdon. His presentation for Software Best Practices Conference is about Ten Most Important Ideas in Software Engineering. Here is what he talks about:
- You can't control what you can't measure
- Peopleware
- Incrementalism
- Iteration
- Repair costs increase
- Tradeoffs are non-linear
- Reuse is important
- Risk management provides insights
- Consistency trumps brillance + death march
- Don't reinvent the wheel
You can download the pdf here.





Recent Comments