Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I have an array like this
int numbers[]={5,6,5,8,9,1,-6516,8,811,981,981};
and I need to print them to screen with spaces in front of them so the total number of characters printed will be 4. si the number 5 will be printed as 3 spaces and 5 5 the number 811 will be 811 and so on.
As was previously mentioned in comments, this is something you can do with printf. I'm reluctant to write the code because a) it looks like homework and b) you'll have this nailed once you've read up on printf. (You'll need to put that printf in a for-loop to go thru the array, for sure, so read up on for as well if you need to.)
Some good resources for printf are whatever textbook you're using, plus
https://www.tutorialspoint.com/c_standard_library/c_function_printf.htm
https://www.dummies.com/programming/c/how-to-format-with-printf-in-c-programming/
http://www.cplusplus.com/reference/cstdio/printf/ (a reference, not a tutorial)
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I know it is not recommended to post code as an image, since I am getting a formatting error when trying to post code on here. Anyway, I am trying to write a simple C program to count number of words, characters, newlines using do while loop. However, the output is not as expected. Please help!
Instead of a do-while, you should try using while. Since your code starts off by checking whether a is any of your if cases, it goes to the else case, and increments the New line variable. If possible, could you share the output screen.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I was wondering how could I print just the last 5 digits of an octal number in C programming language?
Tricky part: the number is unsigned in definition, so after some procedures it outputs something like 3777777464. What I want to print is just 77464.
I tried to look around in C formatting guides, but I only found out how to write the first 5 digits/characters, not the last 5 ones in regards to the tricky part mentioned.
It is only needed to be displayed in output (printf/fprintf in a file).
EDIT and emphasize: The code is too long to post here, It consists of many c files and headers. To make it concise: I need printf("%05o\n",arr[i]); to print only last 5 digits. It prints something like 3777777464. The numbers are correct, I just need the last 5 digits
Thank you very much for helping me
print just the last 5 (octal) digits of a number
Derive the last 5 octal digits by anding with a mask of the 077777.
#define MASK_LAST_5_OCTAL_DIGITS 077777u
// vv print at least 5 characters, pad with 0 as needed
printf("%05o\n", (unsigned) (number & MASK_LAST_5_OCTAL_DIGITS));
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I would like to store 2 variables into char array, and print our the first one as shown below.
const char *a[2];
a[0] = getCapital(bufferStore); //"Australia"
a[1] = getCurrencyCode(bufferStore); "9876.00"
printf("%s", a[0]);
However, I did not get any output. The code of getCapital and getCurrencyCode should be redundant here. The main thing I want to find out is how I can print out "Australia". I'm new to C language and pointers are really hard to understand, and my assignment is due in 2 hours. Any help will be greatly appreciated!
The file stdout, which is what printf writes to, is by default line buffered. That means everything you write to it is buffered, i.e. stored in memory, and is flushed (and actually printed) when you print a newline.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
So lets say I have received a message that resembles the following
"L2N5*8R10!11T0A1K3Y14#4W7O6O9C12R13"
and I am expected to sort out the characters in accordance to the numbers succeeding them and change the characters that are not letters into a space. I have no problem doing the sorting out part, I am only having a trouble while trying to write a function that will change those characters into space.
The out put should be something like this
TALK NOW OR CRY
but I am getting
TALK#NOW*OR!CRY
Can anyone help me figure out what my function should look like so that I can be able to change the characters into space??
Unless you show your code, we'll only be able to guess!!
However, as a general suggestion, I would recommended, you should check each entry against isalpha(). In case you got a return value of 0, replace the entry with a .
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
Can anybody explain the variations in printf syntax..i am confused in some of it
like
printf(5+"hello my friend");//i have problem this addition of 5
printf("hello""my""friend");//i have problem with double apostrophe
what kind of printf prototype do these follows ?
Is this have anything to do with dynamic linking?
Can anybody show some other weird printfs and explain them.
A string in C is accessed via a pointer to a char (see H2CO3's comment for a more precise definition). If you add 5 to a pointer to a char, you start the string 5 characters later. So 5+"hello my friend" points to " my friend", skipping "hello".
When a C compiler sees two strings with nothing (except possibly whitespace) in between, it treats them as a single string. This makes it easier to break long strings in multiple lines.
So "hello""my""friend" compiles into exactly the same thing as "hellomyfriend" or
"hello"
"my"
"friend"
None of these has anything to do with printf, and a lot to do with strings.