Hi,
im filling a 2D array using fscanf and reading from a csv file.
the problem is the file im reading from has some blank spaces which causes any information following to be output as an error.
Is there any way of ignoring the blank spaces in the csv file (excel) and continuing to the next number?
# include<stdio.h >
# include <stdlib.h>
# include<math.h>
int ReadFromFile(in t Array[][30], FILE *inFile);
int main(void)
{
double arrayVal;
int Array[30][30], i, j, x;
char filename[50];
for(i=0;i<28;i+ +)
{
for(j=0;j<28;j+ +)
{
Array[i][j]=0;
}
}
//Get input filename
printf("Enter the filename to read:");
scanf("%50s",fi lename);
//Open file
FILE *inFile;
inFile = fopen(filename, "r");
if(inFile==NULL )
{
printf("Could not properly load file!\n");
getchar();
getchar();
}
else
{
printf("File opened and loaded properly\n\n");
}
for(i=0;i<28;i+ +)
{
for(j=0;j<28;j+ +)
{
Array[i][j]= ReadFromFile(Ar ray, inFile);
printf("The Array Value at Point %d,%d=%i\n", i+1, j+1, Array[i][j]);
}
fscanf(inFile," \n");
}
fclose(inFile);
getchar();
getchar();
}
int ReadFromFile(in t Array[][30], FILE *inFile)
{
int value;
fscanf(inFile," %i,", &value);
printf("the value=%i\n", value);
return (value);
}
thanks
2 11410
It's been a while but I thought fscanf skipped whitespace so it should skip spaces.
Question: If you array is double why are you reading int from the file? If the file actually contains a double, fscanf() will croak on the decimal point.
Question: Why are you reading into tour array with two indexes? There really are no multi-dimensional arrays in C or C++. You might read: http://bytes.com/forum/thread772412.html.
no its not skipping the white spaces cause when i fill the spaces with numbers the program works.
-cant fill the spaces with numbers all the time as that would cause way too much work.
I need a multidimensiona l array to keep information in same order as it is in the csv file
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Blankdraw |
last post by:
....
somewhere, a newbie is dying ...
Is there anybody out there who can help me get the right input
for the following segment? I am trying to read entire records
of 5 (2-digit) integers at a time. It would be best to read the
integers into their own 5 respective variables.
I thought I had it. I've redone my program so many different ways
I am coming to the same conclusion I did when I tried to do it
several years ago: that it cannot...
|
by: Benedicte |
last post by:
Hi,
I'm getting some problems when using fscanf to read a file.
This is a piece of the program code:
main ()
{
/*** Variable declaration ***/
FILE *vpfile; /*** Data file ***/
|
by: learner |
last post by:
I have datafiles like this:
0 1941 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.02 0.00 0.00 1
0 1941 0.00 0.03 0.00 0.03 0.04 0.02 0.00 0.00 0.00 0.00 2
0 1941 0.00 0.00 0.00 0.00 0.52 0.00 0.00 0.17 1.07 0.09 3
0 1941 0.04 0.00 0.00 0.00 0.00 0.62 0.00 0.01 0.00 0.00 4
0 1941 0.00 0.02 0.00 0.00 0.00 0.22 0.00 0.00 0.00 0.16 5
0 1941 0.00 0.00 0.00 0.00 0.09 0.04 0.00 0.00 0.00 0.00 6
0 1941 0.00...
|
by: totoro2468 |
last post by:
Hi, I'm a complete NOOB.
How do I get fscanf to copy into an array? I also need to use malloc,
but where do I put it in my file?
_______________________________________________________
FILE *ifp;
char c;
int y = 0;
txtFile = (char *) malloc(FILELENGTH * sizeof(char)) ;
|
by: quyvle |
last post by:
I can't seem to get this function to work correctly. I'm wondering
if anyone could help me out with this.
So I'm using the fscanf function to read the input stream and store
each string in the appropriate variables.
Here's what I'm reading from another file:
"# Number of power catergories: 9"
| |
by: InuY4sha |
last post by:
Hi,
I hope to be not off topic..
I have a string on a file "00:32:43:54:A2:2D" (let's say a MAC
address)
I use fscanf like this
fscanf( file, "%02X:%02X:%02X:%02X:%02X:%02X",
ptr, ptr+1, ptr+2,
ptr3, ptr+4, ptr+5);
It works, but I get warnings as the expected size is int while I'm
storing onto a uint8_t array.. is there a format to store onto a
|
by: Roman Zeilinger |
last post by:
Hi
I have a beginner question concerning fscanf.
First I had a text file which just contained some
hex numbers:
0C100012
0C100012
....
|
by: David Mathog |
last post by:
Apologies if this is in the FAQ. I looked, but didn't find it.
In a particular program the input read from a file is supposed to be:
+ 100 200 name1
- 101 201 name2
It is parsed by reading the + character, and then sending the
remainder into fscanf() like
|
by: wilco |
last post by:
Hi, I want to copy a csv file into an array using fscanf and keep the blank spaces in the csv file rather than just skip over them to the next number.
there are too many spaces in the csv file to fill them all in manually
I'm using C
any clues how i could do this??
thanks, heres a sample of my code
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |