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);
-
}
Determine the File Count in Unix Directory
May 21, 2008
To determine the number of files in the Unix directory, use the following command.
-
ls -l | grep -c "^-.*"
Merging Files in Unix
May 9, 2008
You have multiple files in containing data in similar format and wanted to consolidate in a single file. This is usually the case if you have a daily log that you want to place an archive copy in a single file in weekly or in monthly, yearly.
The basic syntax of merging file is
-
cat <source file> >> <target file>
If you have more than 10 files to merge it is better to write a shell script that will loop through the files and merge in a file. The following is the code for merging the files in a folder into a single file.
-
#!/bin/sh
-
echo enter file name
-
read filename
-
-
for arg in `ls;`
-
do
-
echo $arg
-
cat $arg >> $filename
-
done
Lines 2 and 3 prompts the user for the filename of the file which will contain the consolidated contents of all the files in the current folder.
Lines 5 to 9 loops through the files in the current folder and merge the files to a single file.
Simplest File Merging
-
#!/bin/sh
-
echo enter file name
-
read source_filemask
-
read master_filename
-
-
cat $arg >> $filename
A simple file merging
-
cat $<filemask>*> $<filename>
Example
-
cat $Test*> $FinalTest.txt
Writing Files in Unix
May 9, 2008
To write files in Unix, the syntax is
-
echo <text> > <filename>
Example
-
echo "This is my message." > myfile.txt
To add another line in the myfile.txt, use the following syntax.
-
echo "This is my second message." >> myfile.txt
You may notice that double greater than sign (>>) is used instead of single greater than sign. This means that the message is written in append mode.
Let's open the myfile.txt by using the following command.
-
tail myfile.txt
The content of the myfile.txt should have the following.
-
This is my message.
-
This is my second message.
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

Things to Do
November 18, 2007
- Tutorials on the following:
- SQL
- PL/SQL
- Oracle Forms
- Unix
- C
- Java
- J2EE
- SOA
- Oracle SOA Suites
- Create a personal blog.
- Update SOA Enterprise
- Review for PL/SQL exam
- Review for Oracle Forms Exam
- Study IBM SOA
- Study UML and Object Oriented Design
- Study SCEA
- Study Oracle SOA
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.
Time to Upgrade Your Skills Towards SOA
November 12, 2007
SOA is still not mature enough but it's evolving fast as the software vendors continues to innovate and improve their SOA products and strategies. According to experts, SOA will be mature in 6 years so it's time for the techies to upgrade their skills and move towards SOA skills such as Java, .NET, SOA suite.
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.
Becoming a Technical Architect
September 11, 2007
After my long vacation, doing something different from my work as an Oracle Retail specialist, I realized that I have a brand new dream. In the past, I'm eager to accelerate my career level progression. I want to move up to a higher position as soon as possible but due to the undesired and unexpected turns of time, this is not a feasible as before.
I'm goal now is to further improve my technical skills and be certified. I started to review for Oracle Certification. I reviewed for 3 months for my examination in 1Z0-007 Introduction to SQL and passed with 90.4%. Now I'm now preparing for Oracle Database SQL Expert Exam which is scheduled on Sept 13, 2007. This is a beta exam which I need to wait for 10 weeks to know the results. After this I'll prepare for PL/SQL exam.
Right now I'm thinking to proceed with certification as an Architect by taking examinations for Sun Certified Enterprise Architect (SCEA). I'm a member of PinoyJUG(Pinoy Java Users Group) and a couple of members are interested taking this specially Sun is offering free examination for this beta examination.
The following are useful links for this certification.





Recent Comments