 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
server Guest
|
Posted: Wed Jan 25, 2006 4:12 pm Post subject: function pointer |
|
|
message unavailable |
|
| Back to top |
|
 |
Jasen Betts Guest
|
Posted: Wed Jan 25, 2006 4:12 pm Post subject: Re: function pointer |
|
|
On 2006-01-10, Roshni <reetdipti (AT) gmail (DOT) com> wrote:
| Quote: | Hi,
I wanted an example of function pointer that tries to access illegal
memory acess.
|
NULL()
Bye.
Jasen
--
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry. |
|
| Back to top |
|
 |
Jasen Betts Guest
|
Posted: Wed Jan 25, 2006 4:12 pm Post subject: Re: incompatible warning in C |
|
|
On 2006-01-10, Ali Labed <labed (AT) nortel (DOT) com> wrote:
| Quote: | incompatible warning in C
typedef struct s_lsp_def;
typedef struct
{
int lsp_id;
int priority;
struct s_lsp_def* ptr_next_lsp_def;
}s_lsp_def;
|
your code nowhere defines what "struct s_isp_def" means.
typedef struct s_isp_def
{
int lsp_id;
int priority;
struct s_lsp_def* ptr_next_lsp_def;
}s_lsp_def;
Bye.
Jasen
--
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry. |
|
| Back to top |
|
 |
Jasen Betts Guest
|
Posted: Wed Jan 25, 2006 4:12 pm Post subject: Re: lvalue assignment error |
|
|
On 2006-01-10, Remco Rijnders <remco (AT) webconquest (DOT) com> wrote:
| Quote: | void *blech; /* yeah yeah, I know, I know. */
(char *) blech = strdup(s);
|
| Quote: | Removing the first (char *) is what's needed to get this section of code to
compile. It also compiled fine when I was on a 32 bit platform and with an
older (pre 4.0) GCC compiler.
I seek to understand why I get this error.
|
I'm sure I saw it in the manual somewhere.
try under extensions, lvalues.
| Quote: | While I've read to never cast return values,
|
the above code is not.
| Quote: | I don't see why that would give an error here seeing how the
man page for strdup says a character pointer is returned.
|
Bye.
Jasen
--
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry. |
|
| Back to top |
|
 |
Jasen Betts Guest
|
Posted: Wed Jan 25, 2006 4:12 pm Post subject: Re: make editor using C |
|
|
On 2006-01-10, nsh4all <nsh4all (AT) gmail (DOT) com> wrote:
| Quote: | Hi all,
I want a source code for making a simple text editor using C
language. Please anyone help me for this.
Thanks in advance,
nsh.
|
something like nano?
--
Bye.
Jasen
--
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry. |
|
| Back to top |
|
 |
Jasen Betts Guest
|
Posted: Wed Jan 25, 2006 4:12 pm Post subject: Re: The old "making change" program |
|
|
On 2006-01-10, Chris <cmlally (AT) gmail (DOT) com> wrote:
| Quote: | Hi everybody,
My new C programming class is absolutely kicking my butt. I have not
been able to devote the time necessary to work on it at times, and am
now falling behind. This is the task I have been given:
|
you'd better catch up fast...
| Quote: | Write a C function named change() that accepts a floating point number
of total coins and the addresses of the integer variables named
quarters, dimes, nickels, and pennies. The function should determine
the number of quarters, dimes, nickels, and pennies in the total coins
number passed to it and write these values directly into the respective
variables declared in its calling function using pointers.
I am not sure where to begin since they want multiple calls to the same
program. Please help.
|
no, to the same function.
| Quote: | Call the function change() from main() three times and print out the
contents of the variables quarters, dimes, nickels, and pennies after
each function return.
|
for example.
int main(void)
{
int q,d,n,p;
float amt;
amt=1.88;
change(amt,&q,&d,&n,&p);
printamt(amt,q,d,n,p);
amt=.32;
change(amt,&q,&d,&n,&p);
printamt(amt,q,d,n,p);
getuseramt(&amt);
change(amt,&q,&d,&n,&p);
printamt(amt,q,d,n,p);
return 0;
}
you'll have to write change(), printamt() and getuseramt(),
comment and debug, the above should it need it.
Bye.
Jasen
--
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry. |
|
| Back to top |
|
 |
Jasen Betts Guest
|
Posted: Wed Jan 25, 2006 4:12 pm Post subject: Re: cannot understand the character handling Program |
|
|
On 2006-01-10, siva <siva215 (AT) gmail (DOT) com> wrote:
| Quote: | When I am trying to execute a program from "The C Programming Language"
by Dennis Ritchie, I tried to run the following program.I am using
Dev++ as a compiler software. The
Program is presented below.
#include <stdio.h
main()
{
long nc;
nc = 0;
while(getchar() != EOF)
++nc;
printf("%1d\n",nc);
}
Whatever I am typing, It is displayed in the black window. I am not
able to reach the EOF as specified in the While statement even after
giving a considerable inputs. I have 2 questions.
1st is I simply cannot understand the logic of the program
even after going through it.
Whatever the input we are typing in is appearing in the window. Is
there any where the data is being stored. I would be thankful if
someone could explain the use of the program in layman's language.
|
no. the content of the input is geing ignored only the length is being
counted... the characters you type are appearing because that it the
default behavior of the operating-system.
| Quote: | 2nd question is, we are using the EOF to compare it with a
value. Is it necessary to specify the EOF value before we use it in a
comparison?.
|
keyboard EOF is somewhat operating-system specific.
Try ctrl-Z , ctrl-D , or alt-255
you may need to type it between pressing enter.
enter ctrl-z enter
| Quote: | printf("%1d\n",nc);
^ |
the character between the % and the d should be a lower case L not a
digit one.
Bye.
Jasen
--
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry. |
|
| Back to top |
|
 |
Ulrich Eckhardt Guest
|
Posted: Wed Jan 25, 2006 4:12 pm Post subject: Re: lvalue assignment error |
|
|
Remco Rijnders wrote something like:
| Quote: | void *blech; /* If you knew you wouldn't do it. */
[...]
(char *) blech = strdup(s);
When I try to compile this code the compiler bails out throwing an
"invalid lvalue in assignment" error in my face.
|
Right so. The cast is treated as the creation of an anonymous, temporary
object of type 'char*', and you are now assigning to this temporary. If
you cast, you should cast the value at the right side of the assignment.
| Quote: | I seek to understand why I get this error. While I've read to never cast
return values, I don't see why that would give an error here seeing how
the man page for strdup says a character pointer is returned.
|
You're not casting the returnvalue but the lvalue on the other side of the
assignment.
Anyhow:
- Use the right pointer types, that way no type conversions are necessary.
- Don't cast. C already implicitly converts most types. If this gives you
errors or warnings, probably your design is wrong.
- Your use of a global is plain silly, what's that supposed to do?
Uli
--
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry. |
|
| Back to top |
|
 |
Ulrich Eckhardt Guest
|
Posted: Wed Jan 25, 2006 4:12 pm Post subject: Re: cannot understand the character handling Program |
|
|
siva wrote:
| Quote: | When I am trying to execute a program from "The C Programming Language"
by Dennis Ritchie, I tried to run the following program.I am using
Dev++ as a compiler software. The Program is presented below.
#include <stdio.h
main()
|
It's 'int main', any book teaching other things is probably obsolete. Yes,
even if it was written by one of the inventors of the language.
| Quote: | while(getchar() != EOF)
[...]
Whatever I am typing, It is displayed in the black window. I am not
able to reach the EOF as specified in the While statement even after
giving a considerable inputs.
|
What is a considerable inputs?
| Quote: | I have 2 questions.
1st is I simply cannot understand the logic of the program
even after going through it.
Whatever the input we are typing in is appearing in the window. Is
there any where the data is being stored. I would be thankful if
someone could explain the use of the program in layman's language.
|
No, input is not stored anywhere. The program just counts
characters/keystrokes.
| Quote: | 2nd question is, we are using the EOF to compare it with a
value. Is it necessary to specify the EOF value before we use it in a
comparison?. One way what i could think is the EOF value may be the
maximum value that the variable can hold ( In this "Long"). But I am
not sure about it.
|
EOF is a constant defined in the system headers. getchar() returns a
character value or EOF if there is no more data to read. Your problem is
that since you use the keyboard there always can come a new character and
thus getchar() simply sits and waits. There are usually ways to tell a
program that EOF was reached via keyboard, try control-D or control-Z.
Otherwise, redirect a file as input into this program, try
type file.txt | yourprogram.exe
./yourprogram < file.txt
All this EOF handling outside your program depends on the system and its
shell though, it is outside the control of C.
Uli
--
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry. |
|
| Back to top |
|
 |
those who know me have no Guest
|
Posted: Wed Jan 25, 2006 4:12 pm Post subject: Re: make editor using C |
|
|
in comp.lang.c.moderated i read:
| Quote: | I want a source code for making a simple text editor using C
language. Please anyone help me for this.
|
the bsd or gnu versions of ed, both of which supply source, may be a
starting-point.
--
a signature
--
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry. |
|
| Back to top |
|
 |
those who know me have no Guest
|
Posted: Wed Jan 25, 2006 4:12 pm Post subject: Re: lvalue assignment error |
|
|
in comp.lang.c.moderated i read:
| Quote: | I have the following snippet of code that used to compile without warnings
before:
|
you were using an extension of some compiler, which now appears to be gone.
it was a horrible mistake at the outset, good thing it was removed.
| Quote: | void *blech; /* yeah yeah, I know, I know. */
char *sstrdup(const char *s)
(char *) blech = strdup(s);
|
there was no reason for this cast, the compiler already knows (if and) how
to convert between char * and void *.
| Quote: | return (char *) blech;
|
fyi, there was no reason for this cast either.
| Quote: | When I try to compile this code the compiler bails out throwing an "invalid
lvalue in assignment" error in my face.
I seek to understand why I get this error.
|
the result of a cast is not a modifiable lvalue, which is needed for an
assignment to succeed.
--
a signature
--
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry. |
|
| Back to top |
|
 |
Marco Guest
|
Posted: Wed Jan 25, 2006 4:13 pm Post subject: Re: module stub generator for testing? |
|
|
update (and thanks to WillerZ for an alternative solution)
by the way I consider "trivial" as maybe an hour or two to do, this
wasn't because I only program in Perl once in a while.
=============================================
ANN: C module stub generator
There are times when you would like to compile and unit test your code
on a Linux/Windows/Mac desktop when the target hardware or a hardware
sim is not available.
This script will allow you to create code stubs for RTOS calls,
unimplemented code, etc. It can create a global variable for your unit
test driver to manipulate the return from a stubbed function.
It can be found at comp.sources.d , it is written in perl.
Please note that you have to remove the REM on the first line (pretty
obvious) and it has been noted that the posted code gets wrapped around
incorrectly (try opening up your window width or get it via a
newsreader). The getpwnam function is unimplemented on Windows so hack
in something you like. I created this on Linux.
If someone would like to host it, feel free to post a clean version on
a web-site somewhere (I don't have a web-site).
comp.sources.d listing here:
http://tinyurl.com/atsqm
enjoy
--
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry. |
|
| Back to top |
|
 |
Jasen Betts Guest
|
Posted: Wed Jan 25, 2006 4:13 pm Post subject: Globals. |
|
|
does the standard aywhere state that global variables will be initialsed
with 0 if not explicitly initialised?
Bye.
Jasen
--
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry. |
|
| Back to top |
|
 |
Craig Taylor Guest
|
Posted: Wed Jan 25, 2006 4:13 pm Post subject: Re: 5^2 =24,10^2=99 ???why??? |
|
|
It works fine on my system - however - I think I may know what is going on.
Try adding a #include <math.h> to the top of the file.
The reason this needs to be added is that the C compiler needs to know
what type of values the pow function is supposed to take. The standard
defines it as taking double's yet you're passing it integers.
On some systems int's take up a different amount of space than int's and
/ or stored differently. The pow function when it gets linked into the
programs is expecting doubles and then tries to multiply / handle
garbage input leading to the incorrect values.
If this is not it, can you give an example of the type of output you are
getting?
Thanks,
- Craig Taylor
http://www.ctalkobt.net/prog
hannabaal wrote:
| Quote: | hello all
this is my first steps in c programming.
any help for th follwing source code.
why it's giving wrong result for 5 and it multiples.
tku.
#include <stdio.h
#include <stdlib.h
int main(int argc, char *argv[])
{
int nombre;
int r=0 , r1=0;
char again;
do
{ printf("enter nombre\n");
scanf ("%d",&nombre);
r= pow(nombre,2);
r1=nombre*nombre;
printf("Salut...\n%d au carre = %d
!\n%d*%d=%d\n",nombre,r,nombre,nombre,r1);
printf ("do you want another operation? (Y/N)");
scanf ("%s", &again);
}
while(again == 'Y' || again == 'y');
system("PAUSE");
return 0;
}
-- |
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry. |
|
| Back to top |
|
 |
Johannes Weiner Guest
|
Posted: Wed Jan 25, 2006 4:13 pm Post subject: Re: The old "making change" program |
|
|
On 2006-01-10, Chris <cmlally (AT) gmail (DOT) com> wrote:
| Quote: | Hi everybody,
My new C programming class is absolutely kicking my butt. I have not
been able to devote the time necessary to work on it at times, and am
now falling behind. This is the task I have been given:
Write a C function named change() that accepts a floating point number
of total coins and the addresses of the integer variables named
quarters, dimes, nickels, and pennies. The function should determine
the number of quarters, dimes, nickels, and pennies in the total coins
number passed to it and write these values directly into the respective
variables declared in its calling function using pointers.
Call the function change() from main() three times and print out the
contents of the variables quarters, dimes, nickels, and pennies after
each function return.
First Call--pass in the total value $1.88 and on return print the
contents of the variables.
Second Call--pass in the total value .32 and on return print the
contents of the variables.
Third Call--ask for a total value input from the keyboard and on return
print the contents of the variables.
Output should look like:
TOTAL VALUE ENTERED: 1.88
7 quarters
1 dime
0 nickels
3 pennies
and not:
TOTAL VALUE ENTERED: 1.88
7 quarters
18 dimes
37 nickels
188 pennies
I am not sure where to begin since they want multiple calls to the same
program. Please help.
-- |
comp.lang.c.moderated - moderation address: clcm (AT) plethora (DOT) net -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry. |
|
| Back to top |
|
 |
Powered by phpBB © 2001, 2006 phpBB Group
|