473,386 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

how populate an array

Hi all,

I'm working in the C language.

I've been stuck for 2 weeks trying to figure out how in the world to populate arrays after reading in an input FILE. the input file has numbers and words, I need to write a loop that grabs the integers and stores them in an int array, and also store the characters into the char array. Please Help I'm so desparate. My teacher is no help because he just gets angry at you for not knowing. kinda dumb since im just learning how to do it all. (GEEZ.)


here's what i got....

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

void read();

int main()
{
read();
return 0;
}

void read()
{
char w[1000];
int n[1000];
int i;
FILE *f;
f = fopen("intput.txt","r");

while(i < 1000)
{
if (fscanf(f, "%c%d", &w[i], &n[i]) != EOF)
{
printf("%c%d", w[i], n[i]);
}
else
{
break;
}
}
fclose(f);
}

this doesn't work, but I'm stuck.

Thanks for the help
Nov 29 '06 #1
2 2559
smithan
16
Hi all,

I'm working in the C language.

I've been stuck for 2 weeks trying to figure out how in the world to populate arrays after reading in an input FILE. the input file has numbers and words, I need to write a loop that grabs the integers and stores them in an int array, and also store the characters into the char array. Please Help I'm so desparate. My teacher is no help because he just gets angry at you for not knowing. kinda dumb since im just learning how to do it all. (GEEZ.)


here's what i got....

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

void read();

int main()
{
read();
return 0;
}

void read()
{
char w[1000];
int n[1000];
int i;
FILE *f;
f = fopen("intput.txt","r");

while(i < 1000)
{
if (fscanf(f, "%c%d", &w[i], &n[i]) != EOF)
{
printf("%c%d", w[i], n[i]);
}
else
{
break;
}
}
fclose(f);
}

this doesn't work, but I'm stuck.

Thanks for the help
hi,

i understand ur problem..... please go through the link given below..

http://www.metalshell.com/view/source/7/

the program actually helps u read, all u have to do change it is, when u read a line to a buffer, read each character from that line and use isalnum() and isalpha() function to find out if it is an int or a character and place it in the array suitably.......

there is another method as well, read the whole file at once and then try to segregate integers and characters...

smitha
Nov 29 '06 #2
hi,

i understand ur problem..... please go through the link given below..

http://www.metalshell.com/view/source/7/

the program actually helps u read, all u have to do change it is, when u read a line to a buffer, read each character from that line and use isalnum() and isalpha() function to find out if it is an int or a character and place it in the array suitably.......

there is another method as well, read the whole file at once and then try to segregate integers and characters...

smitha
Sweet, thanks for that link. I will definintly try it out to see if I can get any further.

It seems to be the other method you are suggesting because this is my first class in college for computer science and I would think it would be a little easier then the link you suggested.
Nov 29 '06 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Greg Scharlemann | last post by:
I would like to automatically populate a drop down menu when the page loads based on the selection of an item in a different drop down menu. I made a test page that when drop down #1 changes, drop...
10
by: Craig Keightley | last post by:
I have the following array: function showCPUs(){ //name brandID dualCore dualProcessor var cpuItem=; var cpuItem=; var cpuItem=; var cpuItem=; var cpuItem=; var cpuItem=; var cpuItem=;
4
by: Kevin H | last post by:
Apologies in advance if this sounds slow-witted, but I didn't find it here. Need to populate some textboxes on a form. While I could hard code it (the number of options aren't that high), it...
2
by: George | last post by:
Is there a fast way to transfer an Excel range to an array? Example: Excel range is E2:E300 Dim person() as string Thanks, George
11
by: Zordiac | last post by:
How do I dynamically populate a string array? I hope there is something obvious that I'm missing here Option Strict On dim s() as string dim sTmp as string = "test" dim i as integer ...
6
by: Beginner | last post by:
Hi, I'm trying to populate a TreeView from an existing and filled in ListView (lvwBuild). lvwBuild is a basic two column listview which can have any number of rows. I would like the first...
1
by: vj | last post by:
How i can populate all fileds dynamically in jsp page based on contents found in xml file? I have written jsp servlets and java class file. i transferred automatic data from jsp to servlet then to...
0
by: vijendra | last post by:
How i can populate all fileds dynamically in jsp page based on contents found in xml file?I have written jsp servlets and java class file. i transferred automatic data from jsp to servlet then to...
3
by: OliveOyl3471 | last post by:
In Visual Basic.NET 2003, how do you populate a two dimensional array from a text file? I know how to check file existence, open the file for read, etc. I just can't get it to read more than one...
1
by: DavidPr | last post by:
I have a website that requires a visitor to register in order to make a post. I have one or two users that are violating the terms and every day I'm having to delete them. They just re-register,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.