here...theres something wrong it doesnt read all of the file and displays some annoying numbers..i think my code now is right but it isnt when i run the program..whats wrong with it?

#include<iostream.h>
#include<cstring.h>
#include<fstream.h>
struct grocery
{
int barcode;
string prodname;
string category;
float price;
} ;
int main()
{
grocery data[50];
ifstream in;
in.open("grocery.txt");
for(int i = 0;i<50; i++) //this can also be written as for(int i = 0; i < 50; i++) since the size is 50
{
in >> data[i].barcode >> data[i].prodname >> data[i].category >> data[i].price;
}
in.close();
for(int ind = 0;ind<50; ind++)
cout<<data[ind].barcode<<""<<data[ind].prodname<<""<<data[ind].category<<""<<data[ind].price;
return 0;
}
forgot to post what im trying to read
0001    Apples      Fruits      35.00
0002    Banana      Fruits      20.00
0003    Grapes      Fruits      55.00
0004    Kiwi        Fruits      60.00
0005    Lemon       Fruits      50.00
0006    Batteries       Misc        30.00
0007    Charcoal        Misc        15.50
0008    Flashlight      Misc        50.00
0009    Catsup      Condiments  30.00
0010    SoySauce        Condiments  20.00
0011    Vinegar     Condiments  20.00
0012    GravyMix        Condiments  35.00
0013    Curry       Condiments  20.25
0014    Candy       Snacks      20.00
0015    Cookies     Snacks      40.00
0016    Gelatin     Snacks      20.00
0017    Graham      Snacks      35.00
0018    PotatoChips Snacks      20.00
0019    Chicken     Meat        150.00
0020    Hotdog      Meat        90.00
0021    GroundBeef  Meat        170.00
0022    Pork        Meat        180.00
0023    Cereal      Breakfast       70.00
0024    Oatmeal     Breakfast       50.00
0025    PancakeMix  Breakfast       50.00
0026    Beer        Drinks      30.25
0027    Champagne   Drinks      85.50
0028    Coffee      Drinks      20.00
0029    DietSoda        Drinks      20.00
0030    BathSoap        Hygiene     27.50
0031    HandSoap        Hygiene     34.00
0032    HairSpray       Hygiene     50.00
0033    Lotion      Hygiene     55.00
0034    BrownRice   Pasta&Rice  60.00
0035    Lasagna     Pasta&Rice  75.00
0036    Spaghetti       Pasta&Rice  75.00
0037    Cabbage     Vegetable       40.00
0038    Eggplant        Vegetable       30.00
0039    Tomato      Vegetable       20.00
0040    Squash      Vegetable       45.00
0041    Lettuce     Vegetable       45.00
0042    Yoghurt     Dairy       40.00
0043    Butter      Dairy       25.00
0044    IceCream        Dairy       199.00
0045    Milk        Dairy       37.00
0046    Cheese      Dairy       30.00
0047    Bleach      Cleaning        20.00
0048    Sponges     Cleaning        50.00
0049    DishwashingLiquid   Cleaning        30.00
0050    FabCon      Cleaning        20.00

What is the output that you are getting?

Im pretty sure Walt would tell you this but you should use meaningful titles for your threads. Asking for a specific person to check out your code doesnt really say anything about what is going on.

I think you cant post a picture here so its like 539488e..some words are displayed...oh and the barcodes doesnt seem to work....for example instead of 0001 it only displays 1..im using turbo c++ 4.5 compiler by the way...

oh wait my bad...its kinda works now...i wonder how to put spaces

its fixed!!!

#include<iostream.h>
#include<cstring.h>
#include<fstream.h>
struct grocery
{
char barcode[5];
string prodname;
string category;
float price;
} ;
int main()
{
grocery data[50];
ifstream in;
in.open("grocery.txt");
for(int i = 0;i<50; i++) //this can also be written as for(int i = 0; i < 50; i++) since the size is 50
{
in >>data[i].barcode >> data[i].prodname >> data[i].category >> data[i].price;
}
in.close();
for(int ind = 0;ind<50; ind++)

cout<<" "<<data[ind].barcode<<" "<<data[ind].prodname<<" "<<data[ind].category<<" "<<data[ind].price<<"\n";
return 0;

}

You realize that by calling out Walt, you've guaranteed that he'll blast you for not using any formatting and for unnecessarily living in the 90s with Turbo C++, right?

Im surprised I havent seen him yet.

Hmm, does this mean that Walt is the new Narue? Before it was always Narue's sharp tongue that everyone feared. ;)

NathanOliver: Im surprised I havent seen him yet.

Surprise!!!!

deceptikon: Hmm, does this mean that Walt is the new Narue? Before it was always Narue's sharp tongue that everyone feared. ;)

Nyahhhh, I just didn't get logged in for a while. I thought it was 48 hour befor you were missing...

NathanOliver: Im pretty sure Walt would tell you this but you should use meaningful titles for your threads. Asking for a specific person to check out your code doesnt really say anything about what is going on.

Absolutely...

deceptikon: You realize that by calling out Walt, you've guaranteed that he'll blast you for not using any formatting and for unnecessarily living in the 90s with Turbo C++, right?

Formatting, yes. That was my first thought. As for Turbo, I really don't care with half the world stuck in the 80's. It's others that go ballistic over Turbo. I personally like Borland. I can carry it with me.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.