473,406 Members | 2,549 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,406 software developers and data experts.

Playing with array's structures HELP

momotaro
357 100+
am modifying the two arrays in the first function but when I call them for usage in the second seems like they've not beenn modified at all
plz help

Expand|Select|Wrap|Line Numbers
  1. void MonstreFill(Monstre *Squelettique, Monstre *Grassouillet)
  2. void test(Monstre *Squelettique, Monstre *Grassouillet)
  3.  

Expand|Select|Wrap|Line Numbers
  1. void MonstreFill(Monstre *Squelettique, Monstre *Grassouillet)
  2. {
  3.     int i, nbrMonstre, monstreType, monstreTaille;
  4.  
  5.     do
  6.     {
  7.         puts("Nombre de monstre ?");
  8.         scanf("%d", &nbrMonstre);
  9.     }while(nbrMonstre < 1 || nbrMonstre > 10000);
  10.  
  11.     //initialisation
  12.  
  13.     for(i = 0; i < nbrMonstre; i++)
  14.     {
  15.         Squelettique[i].type = 0;
  16.         Squelettique[i].taille = 0;
  17.  
  18.         Grassouillet[i].type = 0;
  19.         Grassouillet[i].taille = 0;
  20.     }
  21.  
  22.     for(i = 0; i < nbrMonstre; i++)
  23.     {
  24.         puts("0->grand monstre, 1->petit monstre? largeur(petit monstre), longueur(grand monstre)?");
  25.         scanf("%d %d", &monstreType, &monstreTaille);
  26.         if(monstreType == 0)
  27.             Squelettique[i].taille = monstreTaille;
  28.         else if(monstreType == 1)
  29.             Grassouillet[i].taille = monstreTaille; 
  30.     }
  31. }


Expand|Select|Wrap|Line Numbers
  1. void test(Monstre *Squelettique, Monstre *Grassouillet)
  2. {
  3.     int i;
  4.     for(i = 0; i < 4; i++)
  5.     {
  6.         printf("monstre %d longuere %d\n", &Squelettique[i].type, &Squelettique[i].taille);
  7.     } 
  8.  
  9. }
Thx in advance
May 3 '09 #1
3 1249
The 1st function works fine, if not very safe.

This is not how you use printf. Drop the &, or you will be displaying the variable address, rather than value.

printf("monstre %d longuere %d\n", Squelettique[i].type, Squelettique[i].taille);
May 3 '09 #2
RRick
463 Expert 256MB
I agree with the above user, your two routines look reasonable.

I would take a look at the pointer values being passed to both of the routines and make sure they are the same. The way your code is set up, the Monstre arrays must be allocated before you call the subroutines.

Take a look at how the arrays are allocated and passed to these routines.
May 5 '09 #3
donbock
2,426 Expert 2GB
What was the operator input during the second 'for' loop in MonstreFill? Notice that if the entered monstreType is neither 0 nor 1 then nothing happens.

When precisely do mean when you say "when I call them for usage in the second seems like they've not been modified at all". Do you mean that ->type and ->taille are always zero?

Notice that MonstreFill does not return the entered value of nbrMonstre. That means that nobody else (the caller or the test function) know how many elements in the Squelettique and Grassouillet arrays were initialized.

I can only assume that you have a static or dynamic allocation of two 10,000-element arrays passed as Squelettique and Grassouillet to MonstreFill. Anything else and there is a strong possibility of memory corruption.
May 5 '09 #4

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

Similar topics

1
by: Peter Schmitz | last post by:
Hi, I'm just trying to play a *.wav file, making use of the unmanaged function "sndPlaySoundA" in winmm.dll, but I still got one question: How can I avoid, that the sound file itself has to be...
4
by: emma middlebrook | last post by:
Hi Straight to the point - I don't understand why System.Array derives from IList (given the methods/properties actually on IList). When designing an interface you specify a contract. Deriving...
7
by: Kathy Tran | last post by:
Hi, Could you please help me how to declare an araay of pointer in C#. In my program I declared an structure public struct SEventQ { public uint uiUserData; public uint uiEvent; public uint...
7
by: Sam | last post by:
Hello I have a structure called Company. struct Company { char *employee; char *employee_address; }; I want to build an array of this structure but the number of employees will change...
12
by: gcary | last post by:
I am having trouble figuring out how to declare a pointer to an array of structures and initializing the pointer with a value. I've looked at older posts in this group, and tried a solution that...
11
by: skumar434 | last post by:
Hi everybody, I am faceing problem while assigning the memory dynamically to a array of structures . Suppose I have a structure typedef struct hom_id{ int32_t nod_de; int32_t hom_id;
29
by: foker | last post by:
I have this problem where I have 2 text files, one with student name, id#, # of courses and course #, the second file has course name and course number. I want to make a multidimensional array that...
44
by: svata | last post by:
Hello, I wonder how to resize such array of structures using realloc()? #include <stdio.h> #include <stdlib.h> #define FIRST 7 typedef struct { char *name;
5
by: =?Utf-8?B?QXlrdXQgRXJnaW4=?= | last post by:
Hi Willy, Thank you very much for your work. C++ code doesnot make any serialization. So at runtime C# code gives an serialization error at "msg_file_s sa = (msg_file_s) bf.Deserialize(ms);"...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
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,...
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
tracyyun
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...
0
isladogs
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...

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.