473,473 Members | 2,008 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Question about printf...

For example...

typedef struct {
int valid;
char name[MAX_NAME];
char lastname[MAX_LASTNAME];
int age;
float note;
char DNI[MAX_DNI];
} TPupil;

TPupil *Ram;

printf ("%10s, %10s %16d %15.2f %15s\n", *Ram->lastname, *Ram->name,
Ram->age, Ram->note, *Ram->DNI);

Why "Ram->age" and "Ram->note" don't need the '*' ?

And, How can I make each follow lines shorter?

(*(Ram + cant - 1)).valid = temp.valid;
(*(Ram + cant - 1)).age = temp.age;
(*(Ram + cant - 1)).note = temp.note;
strcpy( (*(Ram + cant - 1)).DNI, temp.DNI);
strcpy( (*(Ram + cant - 1)).name, temp.name);
strcpy( (*(Ram + cant - 1)).lastname, temp.lastname);

Apr 27 '06 #1
1 1527
Olaf "El Blanco" wrote:
For example...

typedef struct {
int valid;
char name[MAX_NAME];
char lastname[MAX_LASTNAME];
int age;
float note;
char DNI[MAX_DNI];
} TPupil;

TPupil *Ram;

printf ("%10s, %10s %16d %15.2f %15s\n", *Ram->lastname, *Ram->name,
Ram->age, Ram->note, *Ram->DNI);

Why "Ram->age" and "Ram->note" don't need the '*' ?
None of them do.

*Ram->lastname is the first character in Ram->lastname, that is
Ram->lastname[0].
And, How can I make each follow lines shorter?
use a temporary,

TPupil* tmp = Ram+(cant - 1);

tmp->valid = temp.valid;

and so on.
(*(Ram + cant - 1)).valid = temp.valid;
(*(Ram + cant - 1)).age = temp.age;
(*(Ram + cant - 1)).note = temp.note;
strcpy( (*(Ram + cant - 1)).DNI, temp.DNI);
strcpy( (*(Ram + cant - 1)).name, temp.name);
strcpy( (*(Ram + cant - 1)).lastname, temp.lastname);


--
Ian Collins.
Apr 27 '06 #2

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

Similar topics

9
by: Wenjie | last post by:
Hello, Is printf("%d", var); OK for the unsigned long var = SOME_VAR? Or should some other print format be specified? Thanks and best regards, Wenjie
17
by: herrcho | last post by:
#include <stdio.h> int main() { int i; char *p="sarang"; for(i=0;i<4;i++) printf("%c",*(p+i)); printf("\n"); for(i=0;i<4;i++)
2
by: yezi | last post by:
Hi, ALl: The following code is to canculate 2 vector distance. Suppose the vectore is stored in some txt file like -1 0.34 0 0.045 1 0.98 1 0.01
3
by: kkk | last post by:
I am practicing LRU by writing a simulating c programme, but encounter a problem. The problem is when a page hit occurred (simulated process request (contains requested page) a page, which has...
9
by: william | last post by:
When implementing Linked list, stack, or trees, we always use pointers to 'link' the nodes. And every node is always defined as: struct node { type data; //data this node contains ... node *...
17
by: manuthomas23 | last post by:
I have a question: What will be the value of j in the following code? and why is it so? int i; for( i = 0; i < 1; i++ ) { switch( i ) { case 0: i += 5;
1
by: erizy | last post by:
There are situations that exception could be throw within constructor and we usually employ auto_ptr to protect resources. But if we do not have auto_ptr can we use the following technique to handle...
3
by: golden | last post by:
Hello, I am going to ask a question regarding write and lseek. I will provide code at the end of this, but first some background. I am trying to identify the cause of some latency in...
160
by: raphfrk | last post by:
Is this valid? int a; void *b; b = (void *)a; // b points to a b += 5*sizeof(*a); // b points to a a = 100;
2
by: Giorgos Keramidas | last post by:
On Sun, 05 Oct 2008 18:22:13 +0300, Giorgos Keramidas <keramida@ceid.upatras.grwrote: My apologies. I should have been less hasty to hit `post'. If showtext() is passed a null pointer, it may...
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
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,...
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...
1
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...
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...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.