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

question about struct

82
In an example i found this
We have this struct:
[PHP]struct catalog {
char name[80];
char title[80];
char pub[80];
unsigned date;
unsigned char ed;
} cat[MAX];
[/PHP]

When we fill the cat[i].name i saw this
[PHP]
for(i=0 i<MAX; i++)
printf("Enter name..")
gets(cat[i].name);
if(!*cat[i].name) break;/* what this command do? I mean the !* ?[/PHP]
What is !* ?
Thanks in advance
Aug 20 '07 #1
6 1209
ahoyer
14
When we fill the cat[i].name i saw this
[PHP]
for(i=0 i<MAX; i++)
printf("Enter name..")
gets(cat[i].name);
if(!*cat[i].name) break;/* what this command do? I mean the !* ?[/PHP]
What is !* ?
Hey im not too familiar with php or anything, but the ! is the not operator for conditional statements, as far as the * i think it might be dereferencing a member of the struct, just written unclearly.

so what i think theyre doing is just checking to see if the value that the user entered is null, and if it is then kick out of the loop.

thats my best guess anyways.
Aug 20 '07 #2
weaknessforcats
9,208 Expert Mod 8TB
cat is an array of catalog struct variables.
cat[i] is one of those array elements.
cat[i].name is an array of char that is a member of one of those elements.

In C/C++, the name of an array is the address of element 0. Therefore:

cat[i].name is the address of element 0 of the char name array.

Therefore:

*cat[i].name is element 0 of the name array

Therefore:
!*cat[i].name is true if element 0 of the name array is false.

Element 0 of the name array is false if it is a '\0'.

Therefore:

!*cat[i].name is true of the name is a null string.

This could also have been written as:

if (cat[i].name[0] == '\0') break;
Aug 20 '07 #3
kreagan
153 100+
In an example i found this

When we fill the cat[i].name i saw this
[PHP]
for(i=0 i<MAX; i++)
printf("Enter name..")
gets(cat[i].name);
if(!*cat[i].name) break;/* what this command do? I mean the !* ?[/PHP]
What is !* ?
Thanks in advance
The question should probably be: What is "!" and what is "*". It might make more sense to write that line:

Expand|Select|Wrap|Line Numbers
  1. if ( !(*cat[i].name)) break;
The "!" means not and the * is most likely dereferencing a pointer. If there is no value in cat[i].name, then break.

This is only a guess. Some languages see primatives (int, char) as "TRUE". So if there is no value in cat[i].name, then *cat[i].name should return NULL. NULL is FALSE. Therefore !NULL = TRUE.

Hope this helps.
Aug 20 '07 #4
kalar
82
I also think about pointers but. When we have as example an array p[i] and we use a pointer pp for the array, we don't say *pp[i] but only *pp.Am i wrong?


edit:Maybe help you that the programm says that if we enter an empty line in the name breaks
Aug 20 '07 #5
kreagan
153 100+
I also think about pointers but. When we have as example an array p[i] and we use a pointer pp for the array, we don't say *pp[i] but only *pp.Am i wrong?


edit:Maybe help you that the programm says that if we enter an empty line in the name breaks
Are you sure *pp.Am is how you use pointers for an array? With *pp[i].Am, you are stating ... get the value of AM of the ith element of pp.

pp.Am doesn't really make sense to me because there are multiple Ams. I could be mistaken though.
Aug 20 '07 #6
JosAH
11,448 Expert 8TB
Did anyone actually *read* post #3? WeaknessForCats actually explained what
that expression is all about. No need for guessing anymore.

kind regards,

Jos
Aug 20 '07 #7

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

Similar topics

1
by: kazack | last post by:
Hi all it's me again with another question as I got further in my book. The chapter I am in covers structres, abstract data and classes. I only read through to the end of the coverage on...
23
by: Serve La | last post by:
When I write a medium to large sized C application I tend to create structures first, then makeStruct and freeStruct functions that dynamically allocate/free the struct and then I create a bunch of...
1
by: rahul8143 | last post by:
hello, In kernel source code there is ip_fragment.c file my question is regarding pointer function and casting for that look at required snippet from that file There is structure defined for...
16
by: Duncan Mole | last post by:
Hi, This is probably an easy one but it iy first bit of p/invoke. I am trying to use the following C struct in a call: typedef struct { BYTE SRB_Cmd; BYTE SRB_Status, BYTE ...
5
by: Brian | last post by:
I am "learning" C# and have run into a problem that, though I can work around it, I would like to know what the *right* way to handle the issue is. I have created an "Info" struct and assigned...
19
by: lawtrevor | last post by:
I have a question regarding the use of free() based on some code I need to decipher: { struct A {<A fields>}; struct B {<A fields+ <Bfields>}; typedef struct A Aobj; typedef struct B Bobj;
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...
21
by: Chad | last post by:
At the following url http://c-faq.com/lib/qsort2.html, they have the following Q: Now I'm trying to sort an array of structures with qsort. My comparison function takes pointers to structures,...
4
by: hugo.arregui | last post by:
Hi! I have two struts like that: struct { int num; int num2; struct b arrayOfB; } a;
5
by: =?Utf-8?B?SmVzc2ljYQ==?= | last post by:
Hello, I have a pInvoke question. This is the C function that is exported from one of the C dll, extern __declspec(dllexport) IM_RET_CODE ST_import (IM_MODE mode, char *filename,...
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: 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
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
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...

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.