473,473 Members | 1,456 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Expected Expression with strcmp

2 New Member
struct Person
{
const char *personName;
int personAge;
struct Person* next;
}P;

int comp_person_name(const void *a, const void *b){

int result = strcmp(((P *)a)->personName,((P *)b)->personName);
return result;

}

The above gives me an error in the line with strcmp. It says Expected expression. Can't inderstand why
Dec 1 '14 #1
3 2835
weaknessforcats
9,208 Recognized Expert Moderator Expert
You need to typecast to your typename and not your variable name:

Expand|Select|Wrap|Line Numbers
  1. int result = strcmp(((Person*)a)->personName, ((Person*)b)->personName);
Dec 1 '14 #2
adiupadhyay03
2 New Member
I tried doing that also, but then it complains

part4.c:19:24: error: use of undeclared identifier 'Person'
int result = strcmp(((Person *)a)->personName,((Person *)b)->per...
^
part4.c:19:32: error: expected expression
int result = strcmp(((Person *)a)->personName,((Person *)b)->per...

and I have changed my struct to ->

struct Person
{
const char *personName;
int personAge;
struct Person* next;
};
Dec 1 '14 #3
donbock
2,426 Recognized Expert Top Contributor
A cast like (Person *) assumes there is a type named Person. Only a typedef can create a new type name like that. The OP code does not contain a typedef -- it only has a structure definition.

Replace (Person *) with (struct Person *) ... or add a typedef to define Person as a type that is equivalent to struct Person.
Dec 1 '14 #4

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

Similar topics

6
by: bayxarea-usenet | last post by:
I am getting the following error during compiling: 'switch expression not integral' I am new to the switch command - here is a snip of my code where I have used this.. .. what is the problem...
9
by: Steven | last post by:
Hello, I have a question about strcmp(). I have four words, who need to be compared if it were two strings. I tried adding the comparison values like '(strcmp(w1, w2) + strcmp(w3, w4))', where...
7
Sieira
by: Sieira | last post by:
I hope you understand my poor english This is my function (it used to return int), I got the same error when I compiled it for first time (then it was in the ***** marked line), so I started to...
1
by: opcs | last post by:
here is my complete code, can any one help me why does this error occurs and how to resolve it. also, error is at the line "list.hdr =(list *) malloc(sizeof(struct SkipList));" is the size...
2
by: lordhoban | last post by:
My program was running fine under visual studio, but I moved it over to Linux, and have run into one problem I have no idea how to fix. error: expected expression before 'int' (all the...
10
by: JEFFREY MUSGRAY | last post by:
I have received alot of help from this site and I am grateful. My problem is that I was able to get the first part of code to work. I tested it via the immediate window. I received the compile error...
4
by: KBeggs | last post by:
Hi. I'm working on a program for a class that requires me to make a checking account simulator. However, every time I try to compile it, I get errors. I have gotten it down to very minimal errors,...
1
by: Jeevan83 | last post by:
Hi, I gott his error after compiling. I could not find the error, whats the error please? error: error: expected expression before ‘{’ token item={"rice",10,40,30}; #include<stdio.h>...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
jinu1996
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...
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
agi2029
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,...
1
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.