I BADLY NEED YOUR HELP......
HELP... hOW TO Pass value to a struct type and permanently store the data after youve given the data.The programming language is C.
My problem is that as I exit the function "int reg(struct Member listm[], int msize);", the data Ive entered was not stored in the array. -
#include <stdio.h>
-
#include <conio.h>
-
#include <string.h>
-
-
struct Member
-
{
-
char name[50];
-
char address[50];
-
int age;
-
char gender;
-
int memID[50];
-
};
-
-
struct Video
-
{
-
char title[50];
-
char genre[50];
-
int borrow[50];
-
int videoID[50];
-
};
-
-
int reg(struct Member listm[], int msize);
-
main()
-
{
-
struct Member listm[50];
-
struct Video listv[50];
-
int choice, again=0;
-
int i;
-
-
/*
-
for (i=0; i<50; i++)
-
{
-
listm[i].memID[i]=0;
-
listv[i].videoID[i]=0;
-
listv[i].borrow[i]='A';
-
}*/
-
-
clrscr();
-
printf("\nWELCOME TO ANIME VIDEO RENTAL SHOP");
-
printf("\nWhat do you want to do?");
-
printf("\n1. Register (if not yet a member)");
-
scanf("%d", &choice);
-
again=reg(listm, 50);
-
getch();
-
return(0);
-
-
}
-
-
int reg(struct Member listm[], int msize)
-
{
-
struct Member *mlist[50];
-
static int i;
-
mlist[50]=&listm[msize];
-
-
printf("\nName: ");
-
scanf("%s", &mlist[i]->name);
-
fflush(stdin);
-
-
printf("\nAddress: ");
-
scanf("%s", &mlist[i]->address);
-
fflush(stdin);
-
-
printf("\nAge: ");
-
scanf("%d", &mlist[i]->age);
-
fflush(stdin);
-
-
i++;
-
-
return(0);
-
}
-
4 2426
I read your code wrong. Hang on.
This code:
scanf("%s", &mlist[i]->name);
Looks fishy. Maybe it should be: -
scanf("%s", &listm[i]->name);
-
An what's this for?
struct Member *mlist[50];
static int i;
mlist[50]=&listm[msize];
Here you declare an array of 50 pointers but only initialize the last pointer.
Then, you use the uninitialized pointers in youre scanf().
It doesn't look like you need the mlist array at all.
Lastly, why a static variable??? The static keyword is largely deprecated in C++.
thanks..uhm can you help me how to store a data in an array in a function?that is after i exit the function, it will still be stored?
thanks..uhm can you help me how to store a data in an array in a function?that is after i exit the function, it will still be stored?
You can't pass an array to a function. All you can pass is a type or a pointer to a type.
In the case of an array, C++ treats the name of the array as the address of element 0. So, when you pass an array, you are really passing the address of element 0.
When the function works with the array, since it only has the address of the array, any change to the array made by the function will be put in the array.
Therefore:
[quote=jadeivel7 56]
int reg(struct Member listm[], int msize)
{
etc...
[/quote
any change made to the array using listm are made to the array itsself since listm is just a pointer to element 0.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Abhas |
last post by:
> > Hi, this is Abhas,
> > I had made a video library program in C++, but was facing a problem.
> > After entering 12 movies, i cannot enter any more movies.
> > Something gibberish comes instead.
> > Can somebody please tell whats wrong??
> > This is the code : :
#include<fstream.h>
#include<conio.h>
|
by: Dave Cooke |
last post by:
Hi I am very new to C. I am trying to figure out how to initialize
a struct in my main program.
The struct is declared in anouther header file like this...
typedef struct ln {
int key;
int data;
struct ln *next;
} listNode, *listNodePtr;
just to test in my main method I tried to initialize the
|
by: Mark Richards |
last post by:
I've been programming for many years, but have only recently taken a
deep "C" dive (bad pun, i know) and need a lot of explanation from an
expert. My questions center around those mysterious pointer beasties.
The following code is excerpted from digitemp, a program that reads
1-wire devices. Digitemp is the work of Brian C. Lane.
As I walk through this code, I have a number of questions. I'm hoping
someone with experience in...
|
by: Don |
last post by:
I have a third party C++ DLL that I am trying to use from C#. The
specific function I am trying to use is declared in C++ as follows:
ladybugConvertToMultipleBGRU32(
LadybugContext context,
const LadybugImage* pimage,
unsigned char* arpszDestBuffers,
LadybugImageInfo* pImageInfo );
|
by: leo2100 |
last post by:
Hi, I need help with this program. The program is supposed to take a
text file and identify the words in it, then it should print them and
count how many times a word is repeated. At first main called the
function wordcount, and then the function did everything including
printing out the results. That worked. Now I want to make the function
return an array of pointers to struct palabra so the calling function
can manage the data as it...
| |
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 looked
sensible, but it didn't work right. Here is a simple example of what
I'm trying to accomplish:
// I have a hardware peripheral that I'm trying to access
// that has two ports. Each port has 10 sequential
// registers. Create a...
|
by: Bill |
last post by:
Hello All,
I am trying to pass a struct to a function. How would that best be
accomplished?
Thanks,
Bill
|
by: dreiko466 |
last post by:
(sorry about my english...)
I am a newbie in C (3 month expierience)
I have wrote a simple test programm in VS2005, what i do wrong?Please...
In this programm i create a double linked list.Then pass its first block pointer
inside the structure Array to Array ->first and the last block pointer inside the structure Array to Array ->last.So i can manipulate the double linked list as a dynamic array. The cells of this dynamic array are...
|
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: 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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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: 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: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |