full in the blank , making use of a[10] to outputcontent of i

  • Thread starter liking C lang.Chinese
  • Start date
L

liking C lang.Chinese

#include<stdio.h>
main()
{
int i;
char a[10];
scanf("%d",&i);
_________________
_________________\\*full in the blank , making use of a[10] to
outputcontent of i*\\
printf("%s",a);
}

can anyone help me?
 
C

CBFalconer

liking C lang.Chinese said:
#include<stdio.h>
main()
{
int i;
char a[10];
scanf("%d",&i);
_________________
_________________\\*full in the blank , making use of a[10] to
outputcontent of i*\\
printf("%s",a);
}

can anyone help me?

We don't do homework. Hint, read the C standard for library
functions. However ...

Your instructor has given you an impossible task, because the
outline program is invalid in the first place. main returns an
int, and should be written as "int main(void)" anyhow (must be for
C99). The program fails to return a value, which is invalid for
C90. So regardless of what standard you use, the program is
invalid.

Find an instructor or course that at least knows the subject they
are trying to teach.

--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfocus.com/columnists/423>

"A man who is right every time is not likely to do very much."
-- Francis Crick, co-discover of DNA
"There is nothing more amazing than stupidity in action."
-- Thomas Matthews
 
L

liking C lang.

liking C lang.Chinese said:
#include<stdio.h>
main()
{
int i;
char a[10];
scanf("%d",&i);
_________________
_________________\\*full in the blank , making use of a[10] to
outputcontent of i*\\
printf("%s",a);
}
can anyone help me?

We don't do homework. Hint, read the C standard for library
functions. However ...

Your instructor has given you an impossible task, because the
outline program is invalid in the first place. main returns an
int, and should be written as "int main(void)" anyhow (must be for
C99). The program fails to return a value, which is invalid for
C90. So regardless of what standard you use, the program is
invalid.

Find an instructor or course that at least knows the subject they
are trying to teach.

--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfocus.com/columnists/423>

"A man who is right every time is not likely to do very much."
-- Francis Crick, co-discover of DNA
"There is nothing more amazing than stupidity in action."
-- Thomas Matthews

Thank you very very very much.
 
L

liking C lang.

liking C lang.Chinese said:
#include<stdio.h>
main()
{
int i;
char a[10];
scanf("%d",&i);
_________________
_________________\\*full in the blank , making use of a[10] to
outputcontent of i*\\
printf("%s",a);
}
can anyone help me?

We don't do homework. Hint, read the C standard for library
functions. However ...

Your instructor has given you an impossible task, because the
outline program is invalid in the first place. main returns an
int, and should be written as "int main(void)" anyhow (must be for
C99). The program fails to return a value, which is invalid for
C90. So regardless of what standard you use, the program is
invalid.

Find an instructor or course that at least knows the subject they
are trying to teach.

--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfocus.com/columnists/423>

"A man who is right every time is not likely to do very much."
-- Francis Crick, co-discover of DNA
"There is nothing more amazing than stupidity in action."
-- Thomas Matthews

but I use the toolis truboc2.0 .
 
G

Guest

CBFalconer said:
liking C lang.Chinese said:
#include<stdio.h>
main()
{
int i;
char a[10];
scanf("%d",&i);
_________________
_________________\\*full in the blank , making use of a[10] to
outputcontent of i*\\
printf("%s",a);
}

can anyone help me?

We don't do homework. Hint, read the C standard for library
functions. However ...

Your instructor has given you an impossible task, because the
outline program is invalid in the first place. main returns an
int,

And main() is declared as returning int.
and should be written as "int main(void)" anyhow (must be for
C99).

Must be for C99, but for C90, it's more style than anything.
The program fails to return a value, which is invalid for
C90.

No, it's valid. You can't assume it will return a successful status,
but it will return properly.
 
L

liking C lang.

#include<stdio.h>
main()
{
int i;
char a[10];
scanf("%d",&i);
_________________
_________________\\*full in the blank , making use of a[10] to
outputcontent of i*\\
printf("%s",a);
}
can anyone help me?
We don't do homework. Hint, read the C standard for library
functions. However ...
Your instructor has given you an impossible task, because the
outline program is invalid in the first place. main returns an
int, and should be written as "int main(void)" anyhow (must be for
C99). The program fails to return a value, which is invalid for
C90. So regardless of what standard you use, the program is
invalid.
Find an instructor or course that at least knows the subject they
are trying to teach.
"A man who is right every time is not likely to do very much."
-- Francis Crick, co-discover of DNA
"There is nothing more amazing than stupidity in action."
-- Thomas Matthews

but I use the toolis truboc2.0 .- Òþ²Ø±»ÒýÓÃÎÄ×Ö -

- ÏÔʾÒýÓõÄÎÄ×Ö -

but i use the tool is turboc2.0
 
P

pete

liking said:
#include<stdio.h>
main()
{
int i;
char a[10];
scanf("%d",&i);
_________________
_________________\\*full in the blank , making use of a[10] to
outputcontent of i*\\
printf("%s",a);
}

can anyone help me?

/* BEGIN new.c */

#include<stdio.h>

int main(void)
{
int i;
size_t count;
unsigned char a[sizeof i + 1] = {0};

puts("Enter an integer.");
if (scanf("%d", &i) == 1) {
for (count = 0; count != sizeof i; ++count) {
a[count] = ((unsigned char *)&i)[count];
}
printf("%s\n", a);
printf("The byte representation of %d is:\n", i);
for (count = 0; count != sizeof i; ++count) {
printf("%u\n", (unsigned)a[count]);
}
}
return 0;
}

/* END new.c */
 
R

Richard

CBFalconer said:
liking C lang.Chinese said:
#include<stdio.h>
main()
{
int i;
char a[10];
scanf("%d",&i);
_________________
_________________\\*full in the blank , making use of a[10] to
outputcontent of i*\\
printf("%s",a);
}

can anyone help me?

We don't do homework. Hint, read the C standard for library
functions. However ...

Your instructor has given you an impossible task, because the
outline program is invalid in the first place. main returns an
int, and should be written as "int main(void)" anyhow (must be for
C99). The program fails to return a value, which is invalid for
C90. So regardless of what standard you use, the program is
invalid.

Find an instructor or course that at least knows the subject they
are trying to teach.

Yes. That will help him pass his course. Congratulations on surpassing
yourself in your desire to show off. And the missing "int" in the
declatation does not, in any way, invalidate the rest of the code for
the sake of this students course.
 
C

Christopher Benson-Manica

Harald van D?k said:
CBFalconer wrote:
No, it's valid. You can't assume it will return a successful status,
but it will return properly.

This exact point has come up several times in many threads on the
group in the past week or so. Perhaps a consensus should be reached
(with help from comp.std.c) and a new FAQ should be created. It
certainly seems to be a recurring cause of rehashed discussion.
 
K

Kenneth Brody

liking C lang.Chinese said:
#include<stdio.h>
main()
{
int i;
char a[10];
scanf("%d",&i);
_________________
_________________\\*full in the blank , making use of a[10] to
outputcontent of i*\\
printf("%s",a);
}

can anyone help me?

Aside from the nitpicking of other parts of this thread, it has yet
to be pointed out that "a[10]" does not exist. You have declared a
as an array of 10 chars, with subscripts running from 0 through 9.
Any attempt to access "a[10]" invokes undefined behavior.

Now, it's possible that your instructor is assuming that the compiler
that you are using will happen to place i at the address that would
have been taken by a[10], if a[10] had existed, and therefore you can
use the assumption that "(int *)(&a[10])" is the same as "&i".

Note, however, that this is a very dangerous assumption to make, and
such code will reformat the hard drive on the DS-6000.

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:[email protected]>
 
L

liking C lang.

liking said:
#include<stdio.h>
main()
{
int i;
char a[10];
scanf("%d",&i);
_________________
_________________\\*full in the blank , making use of a[10] to
outputcontent of i*\\
printf("%s",a);
}
can anyone help me?

/* BEGIN new.c */

#include<stdio.h>

int main(void)
{
int i;
size_t count;
unsigned char a[sizeof i + 1] = {0};

puts("Enter an integer.");
if (scanf("%d", &i) == 1) {
for (count = 0; count != sizeof i; ++count) {
a[count] = ((unsigned char *)&i)[count];
}
printf("%s\n", a);
printf("The byte representation of %d is:\n", i);
for (count = 0; count != sizeof i; ++count) {
printf("%u\n", (unsigned)a[count]);
}
}
return 0;

}

/* END new.c */

thank you very much!
 
N

Nick Keighley

#include<stdio.h>
main()
{
int i;
char a[10];
scanf("%d",&i);
_________________
_________________\\*full in the blank , making use of a[10] to
outputcontent of i*\\
printf("%s",a);

}

can anyone help me?

the code as posted is riddled with bugs and it is not
completly clear what your instructor (YI) wants.

The code uses scanf() to read an int, it does something YI
wants you to fill in, then it uses printf() to print a
string (an array of char) (he forgot to put \n at the end).

So the "someting" that needs to be done is to convert an int
into an array of char. Now have you come across a function
to do this on your course? Or does your textbook mention it?
 
L

liking C lang.

#include<stdio.h>
main()
{
int i;
char a[10];
scanf("%d",&i);
_________________
_________________\\*full in the blank , making use of a[10] to
outputcontent of i*\\
printf("%s",a);

can anyone help me?

the code as posted is riddled with bugs and it is not
completly clear what your instructor (YI) wants.

The code uses scanf() to read an int, it does something YI
wants you to fill in, then it uses printf() to print a
string (an array of char) (he forgot to put \n at the end).

So the "someting" that needs to be done is to convert an int
into an array of char. Now have you come across a function
to do this on your course? Or does your textbook mention it?

Nick Keighley

How can I convert an int into an array of char?
 
K

Keith Thompson

Kenneth Brody said:
liking C lang.Chinese said:
#include<stdio.h>
main()
{
int i;
char a[10];
scanf("%d",&i);
_________________
_________________\\*full in the blank , making use of a[10] to
outputcontent of i*\\
printf("%s",a);
}

can anyone help me?

Aside from the nitpicking of other parts of this thread, it has yet
to be pointed out that "a[10]" does not exist. You have declared a
as an array of 10 chars, with subscripts running from 0 through 9.
Any attempt to access "a[10]" invokes undefined behavior.
[...]

I suspect that the "a[10]" in the comment doesn't refer to element 10
of the array, but to the object a which is an array of 10 elements. I
think it's intended to be an informal notation, similar to the common
use of "foo()" to refer to a function named "foo" rather than to the
result returned by the function "foo".
 
R

Richard Heathfield

Nick Keighley said:
this is hard work sometimes. Some days you wonder if it would
just be easier to give 'em the answer.

Yes, spoonfeeding him would have been a lot quicker than finding K&R2
(which had somehow levitated itself off my desk and buried itself
between "Common Controls and Messages" and UNPv1), and then digging out
the appropriate page reference.
 

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,444
Messages
2,571,709
Members
48,796
Latest member
Greg L.
Top