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

How to find out a type id

hi, guys

I am doing a c program which need me to print out the error message during
the file input, suppose we need to read in a
struct {
int pid;
char *name;
char *skill;
}

I can not guarantee that the input filealways in the oder of pid, name and
then followed by skill in each line, for example,
1
someone
program
somebody
2
gaming
....
so how to I test the readin string's type id (especially the pid int type,
it is differ to other two strings type) in case I can return the error
message.

Thanks guys
Nov 13 '05 #1
3 1675
"zhi lin" <zh*****@ntlworld.com> writes:
I can not guarantee that the input filealways in the oder of pid, name and
then followed by skill in each line, for example,
1
someone
program
somebody
2
gaming
...
so how to I test the readin string's type id (especially the pid int type,
it is differ to other two strings type) in case I can return the error
message.


Strings do not have "type id"s in C. A string is simply a
sequence of characters (followed by a null byte). If the string
contains a sequence of digits, then you can consider it to be a
number. So: read in the input a line at a time. For each line,
test whether it looks like a number by examining its characters.
Based on that, give an error or not.
--
int main(void){char p[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv wxyz.\
\n",*q="kl BIcNBFr.NKEzjwCIxNJC";int i=sizeof p/2;char *strchr();int putchar(\
);while(*q){i+=strchr(p,*q++)-p;if(i>=(int)sizeof p)i-=sizeof p-1;putchar(p[i]\
);}return 0;}
Nov 13 '05 #2
On Sun, 30 Nov 2003 22:54:55 -0000, "zhi lin" <zh*****@ntlworld.com>
wrote:
hi, guys

I am doing a c program which need me to print out the error message during
the file input, suppose we need to read in a
struct {
int pid;
char *name;
char *skill;
}
Unless you wrote the structure during the current execution of the
program, it is probably unlikely that the addresses in the file which
will be read into the two pointers will still point to the data they
did when you wrote the file. It is even questionable whether the
addresses will be part of the current program.

I can not guarantee that the input filealways in the oder of pid, name and
then followed by skill in each line, for example,
1
someone
program
somebody
2
gaming
...
This is inconsistent with you first statement. Are you reading in a
structure or are you reading in data you want to add to a structure?
so how to I test the readin string's type id (especially the pid int type,
it is differ to other two strings type) in case I can return the error
message.

Thanks guys


<<Remove the del for email>>
Nov 13 '05 #3
Ben Pfaff wrote:

"zhi lin" <zh*****@ntlworld.com> writes:
I can not guarantee that the input
filealways in the oder of pid, name and
then followed by skill in each line, for example,
1
someone
program
somebody
2
gaming
...
so how to I test the readin string's type id
(especially the pid int type,
it is differ to other two strings type)
in case I can return the error
message.


Strings do not have "type id"s in C. A string is simply a
sequence of characters (followed by a null byte). If the string
contains a sequence of digits, then you can consider it to be a
number. So: read in the input a line at a time. For each line,
test whether it looks like a number by examining its characters.
Based on that, give an error or not.

I am doing a c program which need me to print out
the error message during the file input,
suppose we need to read in a
struct {
int pid;
char *name;
char *skill;
}


The structure contains pointers to strings, not strings.
In order to know anything about the string,
you would have to dereference the pointer first,
and you're not supposed to do that
until you know whether you have an int, or a pointer.

--
pete
Nov 13 '05 #4

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

Similar topics

9
by: Mayer | last post by:
Hello: I'm running python under cygwin and need to find the drive letter. Cygwin has a way of calling my drives by a name relative to the Cygwin directory, so I get things like /home/user rather...
0
by: Derek | last post by:
I am creating an intranet using Visual Web Developer Express Edition. Everything has been working OK until yesterday when I started getting 62 messages all beginning "Could not find schema...
0
by: Xah Lee | last post by:
Interactive Find and Replace String Patterns on Multiple Files Xah Lee, 2006-06 Suppose you need to do find and replace of a string pattern, for all files in a directory. However, you do not...
1
by: amir | last post by:
Hi, When compiling a page in VS2005 this morning I received 101 messages regarding schema problems in my web.config file. When I go to view an aspx page in my IIS, IE just displays a blank...
5
by: SunnyDrake | last post by:
HI! I wrting some program part of it is XML config parser which contains some commands(for flexibility of engenie). how do i more simple(if it possible not via System.Reflection or...
1
by: winston.heng | last post by:
Hi, Thanks for reading this posting. I have been cracking my head on solving the infinite loop when i call the following section code. Any help or advise is greatly appreciated =D Thanks in...
5
by: YaoBao | last post by:
Is any ColdFusion script I can put on my webpage that will create a search bar so people can type keywords to match it on the current page in my website? It will be exactly like the finder search bar...
7
by: Christian Meier | last post by:
Hello Newsgroup I have a question about the find function of std::set. When I have a "std::set<int*>", why can't I call the find() function with an "const int*"? I know that my key type is...
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
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
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
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...

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.