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

what does this mean??

I got errors:
qu2-1.c:66: warning: format '%s' expects type 'char *', but argument 2
has type 'char (*)[19u]'
qu2-1.c:72: warning: format '%s' expects type 'char *', but argument 2
has type 'char (*)[19u]'

but I don't quite know what it means...
<code/>

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

#define MAXPATIENTS 20

struct details {
int id;
char forename[20];
char initial;
char surname[20];
int day_of_entry;
int max_wait;
};

struct details patient[MAXPATIENTS];
int npatients = 0;

//Functions
int day_now(void);
int read_queue(void);
int list_patient(int index);
int queue_patient(struct details newpatient);
void list_queue();
void write_queue();
int insert_patient(int index, struct details newpatient);
int delete_patient(int index);
int find_patient_id(int id);
//Main starts here
int main (void) {
int Choice;
int id;
int index;
int n;
//Loop that continues the program
while(n < 0){
//To keep program running
//Displaying Menu
printf("\n\n");
printf("_________________________________________\ n");
printf("|-----------NHS Queue Control-----------|\n");
printf("| Create New Patient \t- Press 1\t|\n");
printf("| Delete Patient \t- Press 2\t|\n");
printf("| Find Patient \t\t- Press 3\t|\n");
printf("| List Queue \t\t- Press 4\t|\n");
printf("| Quit \t\t\t- Press 5\t|\n");
printf("|_______________________________________|\ n");
printf("Choice: ");
scanf("%d",&Choice);
printf("\n");
printf("%d \n",day_now());
//Choice made, carrying out function
switch (Choice){
//New Patient
case 1:
index = read_queue() + 1;
printf("Please enter the following details\n");
printf("Patient ID: ");
scanf("%d", &patient[index].id);
printf("Forename: ");
scanf("%s", &patient[index].forename);
printf("\n");
printf("Middle Initial: ");
scanf("%c", &patient[index].initial);
printf("\n");
printf("Surname: ");
scanf("%s", &patient[index].surname);
printf("\n");
printf("Day of Entry (Since 1/1/1970): ");
scanf("%d", &patient[index].day_of_entry);
printf("Maximum Waiting Time: ");
scanf("%d", &patient[index].max_wait);
insert_patient(index, patient[index]);
break;
........

int insert_patient(int index, struct details newpatient) {
//For testing only.....
printf("%d \n",patient[index].id);
printf("%s \n",patient[index].forename);
printf("%c \n",patient[index].initial);
printf("%s \n",patient[index].surname);
printf("%d \n",patient[index].day_of_entry);
printf("%d \n",patient[index].max_wait);
}

May 27 '07 #1
3 4731
In article <11*********************@q66g2000hsg.googlegroups. com>,
ch****@gmail.com <ch****@gmail.comwrote:
>I got errors:
qu2-1.c:66: warning: format '%s' expects type 'char *', but argument 2
has type 'char (*)[19u]'
qu2-1.c:72: warning: format '%s' expects type 'char *', but argument 2
has type 'char (*)[19u]'
Those are warnings, not errors.
>struct details {
int id;
char forename[20];
char initial;
char surname[20];
int day_of_entry;
int max_wait;
};
Notice that forename and surname are fixed length arrays of up
to 20 characters. A fixed length character array does not necessarily
end in a null byte ('\0'), but you are attempting to print the
names using %s format, which is reserved for character arrays that
*do* end in a null byte. The compiler is warning you that this
might be an incompatability -- if you had a forename or surname
which used all 20 characters of the array, then printing that
forename or surname with %s would "fall off the end" of the character
array with undefined results.

If you are -certain- that forename or surname will end in '\0' then you
can either ignore the warnings, or you can cast the type in the
printf() calls.
--
"law -- it's a commodity"
-- Andrew Ryan (The Globe and Mail, 2005/11/26)
May 27 '07 #2
ro******@ibd.nrc-cnrc.gc.ca (Walter Roberson) writes:
In article <11*********************@q66g2000hsg.googlegroups. com>,
ch****@gmail.com <ch****@gmail.comwrote:
>>I got errors:
qu2-1.c:66: warning: format '%s' expects type 'char *', but argument 2
has type 'char (*)[19u]'
qu2-1.c:72: warning: format '%s' expects type 'char *', but argument 2
has type 'char (*)[19u]'

Those are warnings, not errors.
>>struct details {
int id;
char forename[20];
char initial;
char surname[20];
int day_of_entry;
int max_wait;
};

Notice that forename and surname are fixed length arrays of up
to 20 characters. A fixed length character array does not necessarily
end in a null byte ('\0'), but you are attempting to print the
names using %s format, which is reserved for character arrays that
*do* end in a null byte. The compiler is warning you that this
might be an incompatability -- if you had a forename or surname
which used all 20 characters of the array, then printing that
forename or surname with %s would "fall off the end" of the character
array with undefined results.

If you are -certain- that forename or surname will end in '\0' then you
can either ignore the warnings, or you can cast the type in the
printf() calls.
The warnings were on the scanf() calls, not the printf() calls.
(chutsu: it would have saved time if you had told us that yourself.)

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
May 27 '07 #3
ch****@gmail.com wrote:
>
I got errors:
qu2-1.c:66: warning: format '%s' expects type 'char *', but argument 2
has type 'char (*)[19u]'
qu2-1.c:72: warning: format '%s' expects type 'char *', but argument 2
has type 'char (*)[19u]'

but I don't quite know what it means...
<code/>
struct details {
int id;
char forename[20];
struct details patient[MAXPATIENTS];
int npatients = 0;
scanf("%s", &patient[index].forename);
(patient[index].forename) is the name of an array of 20 char.
(array of 20 char) is the type of the expression.
An expression of array type, converts to a pointer to its first element
in all but three cases. So,

scanf("%s", patient[index].forename);

is the right way to write that.

(&patient[index].forename) is the address of an array of 20 char.
(pointer to an array of 20 char) is the type of the expression.
When the name of an array is the operand of the & operator,
is one of the cases where the name of an array doesn't
automatically convert to a pointer.
When it's the operand of sizeof is another case
where the name of an array doesn't
automatically convert to a pointer.
The third case, is when a string literal initializes an array.

--
pete
May 27 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

125
by: Sarah Tanembaum | last post by:
Beside its an opensource and supported by community, what's the fundamental differences between PostgreSQL and those high-price commercial database (and some are bloated such as Oracle) from...
3
by: Jukka K. Korpela | last post by:
I have noticed that the meaning of visibility: collapse has been discussed on different forums, but with no consensus on what it really means. Besides, implementations differ. The specification...
86
by: Michael Kalina | last post by:
Because when I asked for comments on my site-design (Remember? My site, your opinion!) some of you told me never to change anything on font-sizes! What do you guys think of that:...
44
by: lester | last post by:
a pre-beginner's question: what is the pros and cons of .net, compared to ++ I am wondering what can I get if I continue to learn C# after I have learned C --> C++ --> C# ?? I think there...
2
by: Steve Richter | last post by:
What does the "." mean in the following sql script stmts? use GO if exists (select * from dbo.sysobjects where id = object_id(N'.') and OBJECTPROPERTY(id,N'IsUserTable') = 1) drop table ....
121
by: typingcat | last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so on. I've tried many PHP IDEs today, but almost non of them supported Unicode (UTF-8) file. I've found that the only Unicode...
51
by: jacob navia | last post by:
I would like to add at the beginning of the C tutorial I am writing a short blurb about what "types" are. I came up with the following text. Please can you comment? Did I miss something? Is...
1
by: Frank Rizzo | last post by:
Some of the classes in the framework are marked as thread-safe in the documentation. In particular the docs say the following: "Any public static (*Shared* in Visual Basic) members of this type...
13
by: Jason Huang | last post by:
Hi, Would someone explain the following coding more detail for me? What's the ( ) for? CurrentText = (TextBox)e.Item.Cells.Controls; Thanks. Jason
9
by: JoeC | last post by:
m_iWidth = (int)pBitmapInfo->bmiHeader.biWidth; m_iHeight = (int)pBitmapInfo->bmiHeader.biHeight; What does this mean? I have seen v=&var->member.thing; but what does it mean when you...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
Oralloy
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,...

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.