![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Back-to-Back Connection using HBAs | aldowsary | IP Networking | 3 | 11-28-2008 10:21 PM |
| back to back printing in UNIX | amirthraj_12 | AIX | 3 | 05-06-2008 08:42 AM |
| create array holding characters from sring then echo array. | rorey_breaker | Shell Programming and Scripting | 5 | 09-28-2007 09:42 AM |
| From File to Array | Rock | Shell Programming and Scripting | 2 | 02-08-2007 06:10 AM |
| modifying C file and linking back to project files | bruins2005 | UNIX for Dummies Questions & Answers | 1 | 06-23-2006 12:08 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
File to Array and Back.
Hi, how can i write a C program in Red Hat 9. I can't find a compiler.
Also would you mind looking at this code and telling me if you think its ok. I need to put a file which has many columns of data (of which i only need the first two) into an array, so that i can add it to another such file. This is prob very basic, but C is a bit of a mystery to me and i'm only beginning to find my way. #include<stdio.h> void main() { int i,j,array1[][2]; FILE *inp; inp=fopen("file1.txt","r"); for(i=0;i!=EOF;i++) for(j=0;j<2;j++) { fscanf(inp,"%d",&array1[i][j]); } fclose(inp); } What do you reckon? How can i show if this worked, would some simple printf command work? Oh, and to put the final array back into a file? Is that just fprintf? Thanks very much for any help you can provide. |
|
||||
|
1. the gcc compiler is distributed as part of RH. try: Code:
find /usr -name gcc 2. Do not use void main() - it is int main() Code:
int main( int argc, char *argv[])
{
......
......
return 0; <- last line in main()
}
3. the loop will not work to read a file Code:
for(i=0;;i++)
{
test for EOF here
}
so many more errors.... On second thought, you need a C book. try Herbert Schild's book 'Complete C Reference' or one of the SAM's books on C. As for your problem - it can be done in a few lines of awk code. Code:
awk ' {print $1, $2}' myfile > newfile
newfile will have the first two columns of myfile. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|