473,320 Members | 1,900 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,320 software developers and data experts.

problem in struct string

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


struct account {
char AccName[20];
int Age;
double AccBalance;
struct account *Next;
};

typedef struct account BankAcc;

void insert(struct account **headOfList, char *name, int age, double balance);
int Delete(struct account **headOfList, char *name );
void print(struct account *headOfList );
void printAbove50(struct account *headOfList);


void main() {
BankAcc *startPtr = NULL;

int selection;
printf("Enter selection and following below: \n");
printf("1. Insert Account \n2. Delete Account \n3. Print All \n4. Print Age > 50 \n");
printf("Enter your selection : ");
scanf("%d",&selection);

while(selection != 5) {
switch(selection) {
case 1:
char *Username;
char TmpName[20];
int UserAge;
double UserBalance;



// Enter Account Name
printf("Enter Account Name : ");
scanf("%s",&TmpName);
Username = TmpName;
// Enter Age
printf("Enter Age : ");
scanf("%d",&UserAge);
// Enter Account Balance
printf("Enter Account Balance : ");
scanf("%d",&UserBalance);

insert(&startPtr,Username,UserAge,UserBalance);
break;

case 2:
char *del;
char tmpdelete[20];

printf("Enter Account Name : ");
scanf("%s",&tmpdelete);
del = tmpdelete;
Delete(&startPtr,del);
break;

case 3:
print(startPtr);
break;

case 4:
printAbove50(startPtr);
break;
}

printf("---------------------------------------------------------\n");
printf("Enter selection and following below: \n");
printf("1. Insert Account \n2. Delete Account \n3. Print All \n4. Print Age > 50 \n");
printf("Enter your selection : ");
scanf("%d",&selection);
}

}

void insert(struct account **headOfList, char *name, int age, double balance) {
struct account *newPtr;
struct account *previousPtr;
struct account *currentPtr;

newPtr = (account*) malloc(sizeof(account));

if(newPtr != NULL) {

//newPtr->AccName = (char *)malloc(40 * sizeof(char));
strcpy (newPtr->AccName,name);

newPtr->Age = age;
newPtr->AccBalance = balance;
newPtr->Next = NULL;


previousPtr = NULL;
currentPtr = *headOfList;



while(currentPtr != NULL && balance < currentPtr->AccBalance) {
previousPtr = currentPtr;
currentPtr = currentPtr->Next;
}

if(previousPtr == NULL) {
newPtr->Next = *headOfList;
*headOfList = newPtr;
} else {
previousPtr->Next = newPtr;
newPtr->Next = currentPtr;
}
}

//printf("%s\n",headOfList->AccName);

}


int Delete(struct account **headOfList, char *name ){



char mm[20];
strcpy (mm,name);
printf("%s\n",mm);

char m2[20];
strcpy (m2,(*headOfList)->AccName);
printf("%s\n",m2);
//printf("%s\n",(*headOfList)->AccName);

if(mm == m2){
printf("Valid\n");
}





return 0;

}

void print(struct account *headOfList ) {
if(headOfList == NULL) {
printf("List is empty. \n");
} else {
printf("Account Name\tAge\tAccount Balance\n");
printf("__________________________________________ _______\n");

while(headOfList != NULL) {
printf("%s\t%d\t%d\n",headOfList->AccName,headOfList->Age,headOfList->AccBalance);
headOfList = headOfList->Next;
}
}
}


void printAbove50(struct account *headOfList ) {
if(headOfList == NULL) {
printf("List is empty. \n");
} else {
printf("Account Name\tAge\tAccount Balance\n");
printf("__________________________________________ _______\n");

while(headOfList != NULL) {
if(headOfList->Age > 50){
printf("%s\t%d\t%d\n",headOfList->AccName,headOfList->Age,headOfList->AccBalance);
}
headOfList = headOfList->Next;
}
}
}



in my Delete function, if(mm == m2){ printf("Valid\n");} , Valid cannot be printed when mm & m2 have same value, some expert pls help me on this...
Sep 27 '09 #1
1 2117
Banfa
9,065 Expert Mod 8TB
@lye85
No the code says the opposite, Valid will only be printed when mm and m2 have the same value. However mm and m2 can never have the same value so Valid can never be printed.

However mm == m2 compares the values of the address of those 2 arrays. If you actually wanted to compare the 2 strings they contained you would need to call strcmp.
Sep 27 '09 #2

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

Similar topics

57
by: Xarky | last post by:
Hi, I am writing a linked list in the following way. struct list { struct list *next; char *mybuff; };
2
by: ajikoe | last post by:
Hi, I tried to follow the example in swig homepage. I found error which I don't understand. I use bcc32, I already include directory where my python.h exist in bcc32.cfg. /* File : example.c...
1
by: xoinki | last post by:
hi experts, I need a little help in debugging this code.. would u pleeze kindly help me? here this program sends a datagram every 10 seconds and on reception it cheks whether the source IP is...
22
by: sam_cit | last post by:
Hi Everyone, I have the following structure in my program struct sample { char *string; int string_len; };
1
by: Don.Leri | last post by:
Hi, I have a logger.dll (unmanaged c++ dll compiled in vs2005). I have a C# interop to use that dll in managed code implemented in Interfaces.dll (used by other C# dlls). I also have a...
21
by: softwindow | last post by:
#include "stdio.h" #include "malloc.h" struct student{ int age; char *nms; struct student *next; }; struct student *create(){ int ags=0,size=sizeof(struct student); char *nms=" ";
5
by: nick048 | last post by:
Hi to All, Foollowing Your suggestion, I have written this code: #include <stdio.h> #include <string.h> #include <malloc.h> #define BUFLEN 100
19
by: rmr531 | last post by:
First of all I am very new to c++ so please bear with me. I am trying to create a program that keeps an inventory of items. I am trying to use a struct to store a product name, purchase price,...
15
by: vivekian | last post by:
Hi, I have this following class class nodeInfo ; class childInfo { public: int relativeMeshId ;
5
by: Chad | last post by:
say my input file is $ more suck ______ < gnu? > ------ \ , , \ /( )` \ \ \___ / | /- _ `-/ '
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.