many question on C

R

ROSY

hello experts plz answer following questions::: thanks in advance.

1. Out of fgets() and gets() which function is safe to use and why?
2. What is a far pointer? where we use it?
3. What does the error 'Null Pointer Assignment' mean and what causes
this error?
4. What is near, far and huge pointers? How many bytes are occupied by
them?
5. How would you obtain segment and offset addresses from a far
address of a memory location?
6. What are bit fields? What is the use of bit fields in a Structure
declaration?
7. To which numbering system can the binary number 1101100100111100 be
easily converted to?
8. Which bit wise operator is suitable for checking whether a
particular bit is on or off?
9. How can you increase the size of a dynamically allocated array?
10. When reallocating memory if any other pointers point into the same
piece of memory do you have to readjust these other pointers or do
they get readjusted automatically?
11. What is object file? How can you access object file?
12. What do the functions atoi(), itoa() and gcvt() do?
bye,
reply me at (e-mail address removed)
 
J

Joona I Palaste

ROSY said:
hello experts plz answer following questions::: thanks in advance.
1. Out of fgets() and gets() which function is safe to use and why?

fgets(). Definitely. gets() is a bug waiting to happen.
2. What is a far pointer? where we use it?

There is no such thing.
3. What does the error 'Null Pointer Assignment' mean and what causes
this error?

Perhaps you have caused undefined behaviour by indirecting through a
null pointer.
4. What is near, far and huge pointers? How many bytes are occupied by
them?

There is no such thing.
5. How would you obtain segment and offset addresses from a far
address of a memory location?

There is no such thing.
6. What are bit fields? What is the use of bit fields in a Structure
declaration?

The idea is that multiple subsequent bitfields get compressed into the
same byte, saving space. Of course the implementation is not obliged to
do this.
7. To which numbering system can the binary number 1101100100111100 be
easily converted to?

Binary? Other than that, quadrinary, octal, hexadecimal at least. Any
whose radix is a power of 2. Why do you think this is a C question?
8. Which bit wise operator is suitable for checking whether a
particular bit is on or off?

The & operator.
9. How can you increase the size of a dynamically allocated array?

Realloc() it.
10. When reallocating memory if any other pointers point into the same
piece of memory do you have to readjust these other pointers or do
they get readjusted automatically?

Good grief. What do you think? Of course you have to readjust them by
hand. Do you expect the implementation to read your mind?
11. What is object file? How can you access object file?

An object file is what C gets translated to. Accessing it is outside
the scope of C.
12. What do the functions atoi(), itoa() and gcvt() do?

There is no such function as itoa(). atoi() is a poor man's strtol().
There is no such function as gcvt().

I hope I didn't just do your homework for you.

--
/-- Joona Palaste ([email protected]) ---------------------------\
| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste W++ B OP+ |
\----------------------------------------- Finland rules! ------------/
"A friend of mine is into Voodoo Acupuncture. You don't have to go into her
office. You'll just be walking down the street and... ohh, that's much better!"
- Stephen Wright
 
J

jacob navia

ROSY said:
hello experts plz answer following questions::: thanks in advance.
Yes, sure. Here, I did your assignment for you
1. Out of fgets() and gets() which function is safe to use and why?
gets

2. What is a far pointer? where we use it?

a far pointer is a pointer that addresses data smaller than 64K
3. What does the error 'Null Pointer Assignment' mean and what causes
this error?

This error is caused when the program does a = NULL;
4. What is near, far and huge pointers? How many bytes are occupied by
them?

near uses 4 bytes, far uses 2 bytes, and huge uses 1 byte

5. How would you obtain segment and offset addresses from a far
address of a memory location?

segment is pointer/2, offset is pointer + 64K

6. What are bit fields? What is the use of bit fields in a Structure
declaration?

bit fields are arrays of integers
7. To which numbering system can the binary number 1101100100111100 be
easily converted to?

floating point
8. Which bit wise operator is suitable for checking whether a
particular bit is on or off?

the OR operator
9. How can you increase the size of a dynamically allocated array?

with strcat
10. When reallocating memory if any other pointers point into the same
piece of memory do you have to readjust these other pointers or do
they get readjusted automatically?
automatically

11. What is object file? How can you access object file?

Object file is inherited from the FILE class
12. What do the functions atoi(), itoa() and gcvt() do?

atoi: converts integer to ascii
itoa: the inverse, converts ascii to text
gcvt converts unsigned short to unsigned long

Yes, and I hope you do not ever come again
 
J

Joona I Palaste

jacob navia said:
Yes, sure. Here, I did your assignment for you

(snip)

Well done, jacob! I like those answers!

--
/-- Joona Palaste ([email protected]) ---------------------------\
| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste W++ B OP+ |
\----------------------------------------- Finland rules! ------------/
"My absolute aspect is probably..."
- Mato Valtonen
 
S

Slartibartfast

<snip miles of arrogant quips>

Thank you, Jacob, for wasting my bandwidth so that you can feel superior.

Responses like yours are worse than the original posting. At least ROSY (probably) didn't know what she was doing.
 
R

Randy Howard

hello experts plz answer following questions::: thanks in advance.

1. Out of fgets() and gets() which function is safe to use and why?

Neither. Both are very, very, scary. *shudder*. I think you might
want to just stick to something really safe and easy to use for now,
like scanf().
2. What is a far pointer? where we use it?

It is one that is located way off in the distance, like at the bottom
of a 25000 line source file.
3. What does the error 'Null Pointer Assignment' mean and what causes
this error?

A null pointer has been asked to do your homework assignment. It is
causes by students violating their school's code of conduct and/or
ethics rules by soliciting help for homework problems.
4. What is near, far and huge pointers? How many bytes are occupied by
them?

Near pointers are those very close by to your main() function. Or, those
at the very top of a 25000 line source file. FAR has already been
answered in #2. Huge pointers are those used my Microsoft to make your
machine run out of memory. Usually the words "class" and "constructor"
are found to be related to HUGE pointers.
5. How would you obtain segment and offset addresses from a far
address of a memory location?

Well, the segment would be either Home and Small Business, Education,
Federal/Government or Corporate. The offset is the distance between
the address and the nearest 7-11 convenience store.
6. What are bit fields?

Usually 10-20 acres of 0's and 1's. See also Crop Circles.
What is the use of bit fields in a Structure declaration?

Makes them portable to the widest possible variety of system platforms.
Particularly when used with signed short.
7. To which numbering system can the binary number 1101100100111100 be
easily converted to?

Base 72 is my personal favorite. Roman numerals are also possible if you
have not had too much exposure to the Playstation 2.
8. Which bit wise operator is suitable for checking whether a
particular bit is on or off?

Will, the wise operators only come with the professional edition of the
IOCCC Compiler. For your use, stick with the novice operators, they
are much less expensive and can be downloaded from Morpheus at no
charge.
9. How can you increase the size of a dynamically allocated array?

I usually make a hard copy of my source file which contains the array,
then get it slightly damp, water, beer, or Windex all work fine for
this. Then, attach some fishing weights to the bottom of the printout
and use clothespins to hold it high enough off the ground to some
convenient fixture, such as a curtain rod until it stretches out enough
to meet your size requirement.

Note: For those using an IDE, the advanced options/font selection tab
can be used to accomplish the same thing.
10. When reallocating memory if any other pointers point into the same
piece of memory do you have to readjust these other pointers or do
they get readjusted automatically?

Unfortunately, they do not adjust for you. You must instead reassign
a random address to each one, probably via rand(), which will then
cause the C runtime interpreter to automatically fix them up on the
next garbage collection cycle. Note: If you want to use this
feature, you must have selected "optimize for speed" instead of
"optimize for space".
11. What is object file? How can you access object file?

It is the file that holds all of your objects, except for those
declared as "volatile". They are stored in the stack segment
instead. The object file can only be accessed by dereferencing
non-standard platform extensions. On the IBM PC, this is done
by writing the value 0xFE to I/o port 64.
12. What do the functions atoi(), itoa() and gcvt() do?

atoi() returns the arctan of the imaginary component I, but
only if you have an Intel floating point processor. itoa()
is poorly named, but it essentially does the same thing for
a Weitek coprocessor or a Zilog Z-80 in advanced memory
consumption mode. gcvt() is obvious isn't it? It simply
gets the current volatile table for the executing thread
relative to the currently defined XML DTD. (Requires an
ANSI C99 compiler with .NET and XML extensions).
 
N

Neil Cerutti

hello experts plz answer following questions::: thanks in
advance.

Hello ROSY. Please enjoy these answers for their entertainment
value only. If you want more useful answers, acquire and read
_The C Programming Language_ by Kernighan and Ritchie. Be warned
that it doesn't contain the answers to a few of your questions
that turn out not to be C related.
1. Out of fgets() and gets() which function is safe to use
and why?

Neither is safe. The slow emanation from the Hell-curst barrow of
Yogg-Sothoth will inexorably drive you mad whichever you use.
2. What is a far pointer? where we use it?

In the days of yore, the worse was "farp pointer", but the lazy
tongues of humans have eroded one of the "p"s. Back then, farp
pointers were used wherever farps are sold.
3. What does the error 'Null Pointer Assignment' mean and
what causes this error?

It means you are irrevocably doomed. The error is caused by the
slow entropy dissolving the universe.
4. What is near, far and huge pointers? How many bytes are
occupied by them?

A near, far and huge pointer would be enormous, but both intimate
and remote at the same time. It could occupy a thousand bytes and
none at all at once!
5. How would you obtain segment and offset addresses from a
far address of a memory location?

Roll the bones, and consult the resulting oracle.
6. What are bit fields? What is the use of bit fields in a
Structure declaration?

Bit fields are a useless and mostly disused dark corner of C.
Ignore them until you inevitably must maintain the code of one of
the Dark Clerics.
7. To which numbering system can the binary number
1101100100111100 be easily converted to?

At what should I throw the ball at?
In whose bag is the crayon in?
Down which dustbin did I toss this question down?
8. Which bit wise operator is suitable for checking whether
a particular bit is on or off?

You don't need to check this. All bits are on or off by
definition.
9. How can you increase the size of a dynamically allocated
array?

Make it larger.
10. When reallocating memory if any other pointers point into
the same piece of memory do you have to readjust these other
pointers or do they get readjusted automatically?

If they are farp pointers you don't, but it's just the reverse for
other farp type ones.
11. What is object file? How can you access object file?

You should object to most files. They cause nothing put pain and
damnation for those that access them.
12. What do the functions atoi(), itoa() and gcvt() do?

They probably make Jello(tm)-shots and get shnockered while sadly
watching reruns of Three's Company on TV Land.

Bye. I bid you don't look under the bed, lest the last wriggling
tentacle of the damned formian nightmare creature devour thy
compiler and all its libraries.
 
J

jacob navia

Slartibartfast said:
#include <stdio.h>
char*f="#include <stdio.h>char*f=%c%s%c;main(){printf(f,34,f,34,10);}%c";
main(){printf(f,34,f,34,10);}

This will not work. You should eliminate the #include directive since it should
be in a line by itself, and I didn't get to avoiding a problem at the third
generation.

I would propose:

char*f="char*f=%c%s%c;main(){printf(f,34,f,34,10);}%c";
main(){printf(f,34,f,34,10);}

jacob
 
M

Martin Ambuhl

Neil said:
It means you are irrevocably doomed. The error is caused by the
slow entropy dissolving the universe.

This is wrong. "Null pointer assignment" means that your compiler, which
others are inexplicably using without problems, is broken. You should
immediately post to comp.lang.c complaining about the shoddiness of this
product. When someone points out that discussions of the quality of your
compiler are off-topic, or when someone claims (God knows why they would do
so) that your code is hopelessly broken, demonstrate that all those years
reading bathroom walls really did add to your vocabulary.
 
D

Dave Vandervies

This will not work. You should eliminate the #include directive since it should
be in a line by itself, and I didn't get to avoiding a problem at the third
generation.

I would propose:

char*f="char*f=%c%s%c;main(){printf(f,34,f,34,10);}%c";
main(){printf(f,34,f,34,10);}

This invokes undefined behavior by calling a variadic function (printf)
without a prototype, plus it uses implicit int (deprecated in C90, removed
in C99) and (in C90) doesn't return a well-defined value from main.

I would recommend:
--------
int printf(const char *,...);char*f="int printf(const char *,...);\
char*f=%c%s%c;int main(){printf(f,34,f,34,10);return 0;}%c";
int main(){printf(f,34,f,34,10);return 0;}
--------
Second and third generation output are identical (with the \ line-splicing
and the newlines removed, as compared to the original), and compiles
clean with gcc -W -Wall -ansi -pedantic -O.

(Any suggestions on how to remove the ASCII dependency?)


dave
 
J

John Bode

hello experts plz answer following questions::: thanks in advance.

You should know right away that this newsgroup is *not* meant to be a
substitute for a good reference manual. I use Harbison & Steele's "C:
A Reference Manual". 5th edition is the latest (I'm still on 4th ed.;
I hope to get the new one soon). It's a pretty good investment.

You should know that this group is *not* meant to be a quick and easy
way to have your homework done for you.

You should also know that questions that don't pertain directly to the
C language are considered off-topic and will either get no answer or a
smart-ass remark.
1. Out of fgets() and gets() which function is safe to use and why?

The answer should be found in your handy C reference manual (see
Harbison & Steele, 4th ed., p 356).
2. What is a far pointer? where we use it?

Far pointers are an extension to the language introduced by certain
implementations to get around addressing issues in a segmented
architecture. They are not part of the standard C language as such,
and are out of the scope of this particular newsgroup.
3. What does the error 'Null Pointer Assignment' mean and what causes
this error?

It means you screwed up. This really isn't a question about C.
4. What is near, far and huge pointers? How many bytes are occupied by
them?

See my answer to 2.
5. How would you obtain segment and offset addresses from a far
address of a memory location?

See my answer to 2.
6. What are bit fields? What is the use of bit fields in a Structure
declaration?

The answer to this should be found in your handy C reference manual
(Harbison & Steele, 4th ed., pp 136-138).
7. To which numbering system can the binary number 1101100100111100 be
easily converted to?

This is not a question about the C language.
8. Which bit wise operator is suitable for checking whether a
particular bit is on or off?

The answer to this should be found in your handy C reference manual
(Harbison & Steele, 4th ed., p 210).
9. How can you increase the size of a dynamically allocated array?

The answer to this should be found in your handy C reference manual
(Harbison & Steele, 4th ed., p 386).
10. When reallocating memory if any other pointers point into the same
piece of memory do you have to readjust these other pointers or do
they get readjusted automatically?

The answer to this should be found in your handy C reference manual
(Harbison & Steele, 4th ed., pp 387-388).
11. What is object file? How can you access object file?

This is not a question about the C language.
12. What do the functions atoi(), itoa() and gcvt() do?

atoi(): H&S4, p 336-337.
itoa(): Not a standard C function; see sprintf().
gcvt(): Not a standard C function.
bye,
reply me at (e-mail address removed)

Nope, you post here, you read the answers here.
 
M

Malcolm

ROSY said:
1. Out of fgets() and gets() which function is safe to use and why?
gets() crashes computers. fgets() crashes planes. This is because fgets() is
too difficult for the typical programmer to use safely.
2. What is a far pointer? where we use it?
typedef struct
{
int foo;
int bar;
} far;

far *ptr; /* far pointer */

An example use

void fillfar(far *farptr)
{
farptr->foo = 0;
farptr->bar = 1;
}
3. What does the error 'Null Pointer Assignment' mean and what
causes this error?
It means that NULL has been assigned to a pointer. It occurs when a pointer
is assigned to NULL.
4. What is near, far and huge pointers? How many bytes are occupied > by them?
See above for far *s. near and huge pointers can be defined similarly. It is
up to the compiler to decide how many bytes to assign to each pointer.
5. How would you obtain segment and offset addresses from a far
address of a memory location?
These are obviously subfields of the far address, so you mask off the bits
of the address that you don't want.
6. What are bit fields? What is the use of bit fields in a Structure
declaration?
Bitfields are a nice idea. Unfortunately they don't have many uses because
they are typically implemented so poorly, and because they don't necessarily
match any layout in memory. Use AND and OR to perform logical operations on
integers instead.
7. To which numbering system can the binary number
1101100100111100 be easily converted to?
Fibonnacci. Numbers go 1, 1, 2, 3, 5, 8 etc. Very useful for error tolerant
computing, since you never have two ones in a row.
8. Which bit wise operator is suitable for checking whether a
particular bit is on or off?
Try AND work this out for youself, OR ask in comp.programming if you canNOT
do this.
9. How can you increase the size of a dynamically allocated array?
Allocate another array, and copy the contents to it, or call a function
which does this.
10. When reallocating memory if any other pointers point into the same
piece of memory do you have to readjust these other pointers or do
they get readjusted automatically?
I'll give you this one. C has no automatic memory management features -
malloc(), realloc() and free() are just implemented as normal functions that
happen to have access to a large global pool of memory.
If you reallocate a block, it will probably move in memory, and all pointers
to it will become invalid and will not be updated.
11. What is object file? How can you access object file?
"object file" would be a file full of objections. Access like this

FILE *fp;
fp = fopen("file.obj", "rb");
12. What do the functions atoi(), itoa() and gcvt() do?
atoi() is a lie because it doesn't necessarily convert ascii to integer,
sometimes it converts other character systems instead.
itoa() and gcvt() do whatever your implemeter says they do, since they are
not C standard library functions.
 
M

Mike Wahler

Slartibartfast said:
<snip miles of arrogant quips>

Not arrogant, but humorous.
Thank you, Jacob, for wasting my bandwidth so that you can feel superior.

I think Jacob's sense of humor is superior to yours. :)
Responses like yours are worse than the original posting.

Really? I find requests to do classwork quite annoying.
This annoyance is sometimes reduced when a regular responds
with humor. Thanks, Jacob. :)
At least ROSY (probably) didn't know what she was doing.

ROSY knew exactly what she was doing. Trying to cheat
on classwork.

-Mike
 
T

Thomas Stegen

Mike Wahler said:
ROSY knew exactly what she was doing. Trying to cheat
on classwork.

And hence devaluating my degree by lowering the average and
peoples expectation of my performance level. In my opinion
she deserves the mild abuse she is getting.

Why people study somoething that is of no interest to them is
beyond me. I find in stupid and idiotic. Why do they not spend
their time in a more constructive manner?
 
P

Paul Hsieh

jacob navia said:
a far pointer is a pointer that addresses data smaller than 64K

Actually, this is correct. The objects pointed to really do have to
remain < 64K. Only huge pointers allow the target of the pointer to
exceed 64K.
floating point

Depending on your definition of easy ... the complex number base 1+i
would be more convoluted, and surreal numbers would probably be even
more interesting.
the OR operator

Actually by ORing the other bits and compare the result with ~0 is a
sufficient test, and on some RISCs not any different in performance
than using other operators (like & or <<).
 
D

Daniel

This invokes undefined behavior by calling a variadic function (printf)
without a prototype, plus it uses implicit int (deprecated in C90, removed
in C99) and (in C90) doesn't return a well-defined value from main.

I would recommend:
--------
int printf(const char *,...);char*f="int printf(const char *,...);\
char*f=%c%s%c;int main(){printf(f,34,f,34,10);return 0;}%c";
int main(){printf(f,34,f,34,10);return 0;}
--------
Second and third generation output are identical (with the \ line-splicing
and the newlines removed, as compared to the original), and compiles
clean with gcc -W -Wall -ansi -pedantic -O.

(Any suggestions on how to remove the ASCII dependency?)


dave

I'm new to clc, but i *think* I have a guess.
Can't you replace the string _34_ (using underscore to delimit the
boundaries of the string for reasons made obvious in the next
instance) by the string _'\"'_ in both cases? It seems that what's
wanted is the 'quote' character...
And is it ok to simply declare printf without #including <stdio.h>?
 
D

Daniel

This invokes undefined behavior by calling a variadic function (printf)
without a prototype, plus it uses implicit int (deprecated in C90, removed
in C99) and (in C90) doesn't return a well-defined value from main.

I would recommend:
--------
int printf(const char *,...);char*f="int printf(const char *,...);\
char*f=%c%s%c;int main(){printf(f,34,f,34,10);return 0;}%c";
int main(){printf(f,34,f,34,10);return 0;}
--------
Second and third generation output are identical (with the \ line-splicing
and the newlines removed, as compared to the original), and compiles
clean with gcc -W -Wall -ansi -pedantic -O.

(Any suggestions on how to remove the ASCII dependency?)


dave

I'm new to clc, but i *think* I have a guess.
Can't you replace the string _34_ (using underscore to delimit the
boundaries of the string for reasons made obvious in the next
instance) by the string _'\"'_ in both cases? It seems that what's
wanted is the 'quote' character...
And is it ok to simply declare printf without #including <stdio.h>?
 
J

Joona I Palaste

I'm new to clc, but i *think* I have a guess.
Can't you replace the string _34_ (using underscore to delimit the
boundaries of the string for reasons made obvious in the next
instance) by the string _'\"'_ in both cases? It seems that what's
wanted is the 'quote' character...
And is it ok to simply declare printf without #including <stdio.h>?

Yes on both counts. You got the quote thing right, and yes, it is OK to
declare printf() without #including <stdlib.h>. In fact, all #including
<stdio.h> DOES is declare printf() and a bunch of other functions and
macros, most of which aren't even used in the above program. The
compiler only wants the declaration. It doesn't care a hoot about which
file the preprocessor got it from.

--
/-- Joona Palaste ([email protected]) ---------------------------\
| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste W++ B OP+ |
\----------------------------------------- Finland rules! ------------/
"To know me IS to love me."
- JIPsoft
 
D

Dave Vandervies

(e-mail address removed) (Dave Vandervies) wrote in message


I'm new to clc, but i *think* I have a guess.
Can't you replace the string _34_ (using underscore to delimit the
boundaries of the string for reasons made obvious in the next
instance) by the string _'\"'_ in both cases? It seems that what's
wanted is the 'quote' character...

Almost, but not quite. (I spent a while chasing this before I worked out
what the problem with it was, and didn't look too hard for a solution,
so there may be a simple solution that I just didn't see.) What's wanted
is the double-quote character `"', but replacing the _34_ with _'\"'_
runs into the problem that the backslash needs to be escaped in the
string literal to get an escaped `"' in the output.
So if you start with this:
--------
int printf(const char *,...);char*f="int printf(const char *,...);\
char*f=%c%s%c;int main(){printf(f,'\"',f,'\"',10);return 0;}%c";
int main(){printf(f,'\"',f,'\"',10);return 0;}
--------
It outputs this (lines re-wrapped by me):
--------
int printf(const char *,...);char*f="int printf(const char *,...);\
char*f=%c%s%c;int main(){printf(f,'"',f,'"',10);return 0;}%c";
int main(){printf(f,'"',f,'"',10);return 0;}
--------
But the string literal no longer has the double quotes escaped, so
the compiler will choke on it trying to compile the output to get a
second-generation program.

And is it ok to simply declare printf without #including <stdio.h>?

Yep, though it's bad form unless you're trying to play tricks like this
one (which could be argued to be bad form anyways).

The standard headers define types and macros, and declare functions.
As far as the programmer is concerned (though it need not be implemented
this way), including the header is the same as defining the types and
macros and declaring the functions by hand in your code; some of these
(f'rexample, the type size_t and any function that returns a size_t or
takes one as an argument) depend on knowledge that the programmer doesn't
have (or at least should ignore unless it's absolutely necessary), so
including the header is the only portable way to get them, but since
printf only takes and returns basic types (and it's the only thing from
stdio.h that this program needs) including its definition and leaving
out the rest of <stdio.h> is perfectly valid.


dave
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top