All Questions
124 questions
0
votes
2
answers
77
views
Why doesnt it print the array in the second loop like it does in the first one?
The programme below prints the array hello correctly in the first loop. But in the second one all it prints is o. Of course the integer k is pointless but I used it because I thought that the reason ...
1
vote
1
answer
131
views
Uninitialized value error when accessing array bytes via pointer arithmetic in C
I'm working on a C program where I need to display the byte values of an integer array. Here's the code I'm using:
#include <stdio.h>
int main(void)
{
int arr[] = {67305985, 134678021, ...
2
votes
4
answers
355
views
Print numbers of a matrix in a wave pattern
I want the output to be 7 4 1 2 5 8 9 6 3 but it's coming out to be
1 4 7 2 5 8 3 6 9. How can I fix it, and what's the logic behind it so that I can print the reverse wave pattern, too?
#include<...
1
vote
1
answer
87
views
Trouble with getting a function to calculate and loop correctly in C
I am needing to make a program to take user input of iterations to the formula : PI=4(1/1 -(1/3)+(1/5) ... repeating a number of times. MY problems so far is that it is not taking my input accurately.
...
0
votes
1
answer
54
views
How many times will each number be printed if the execvp() fails? I get C 3 times when running but my logic says C 2 times
the code:
int main(int argc, char *argv[]) {
int i;
for (i = 1; i < 3; i++) {
if (fork() == 0) {
printf("A");
execvp("./prog2", &argv[...
0
votes
4
answers
118
views
C Dynamic Array Size
Hello I am new to coding and was just wondering why the below code:
#include <stdio.h>
int main() {
for(int i = 0; 1 ; i++) {
char x;
char z[1+i];
x=getchar();
if (x == '\n'){
...
-3
votes
1
answer
235
views
ternary operator inside printf()
Suppose there is an array of n integers named a. we want to print the elements of this array with the following for loop.
for (int i = 0; i < n; i++) {
printf("%d%c", a[i], &...
0
votes
1
answer
53
views
How to make the strings have the same content?
I have two strings and I am using sprintf in both cases to pass from one format to another from an array or string but in one of the cases it does it well and in the other it does not.
char ...
-1
votes
4
answers
195
views
Printf inside a For Loop
What will this C code print?
for(printf(“1”);!printf(“0”);printf(“2”))
printf(“Sanchin”);
return 0;
I was expecting this code to result in an infinite loop but instead nothing was printed.
Should the ...
1
vote
3
answers
103
views
why does this not print the string?
#include<stdio.h>
#include<stdlib.h>
int main(){
const char *adj[] = {"swag","nice","asparagus","ugly"};
for (int i=0;i<sizeof(adj); i++)...
0
votes
2
answers
118
views
How to print a pyramidal pattern
#include<stdio.h>
int main()
{
int n,i,j,k,m;
printf("Enter the number of lines ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=n-i;...
0
votes
2
answers
281
views
C program for a reverse triangle pattern
I want to draw a pattern like this:
567898765
4567654
34543
232
1
But I can't seem to figure it out, because this is the output I'm currently getting:
567898765
45678987654
3456789876543
...
1
vote
1
answer
48
views
Why the code is not giving the expected output here?
This code is for declaring and printing a string using pointer concept
char *strPtr = "HelloWorld";
// temporary pointer to iterate over the string
char *temp = strPtr;
while (*temp != '\0')...
0
votes
2
answers
75
views
Unexpected behaviour amending a 2d char array with FOR loop
I am trying to amend each character in a 2d array using a FOR loop, but I am getting unexpected results.
#include <stdio.h>
int main() {
char converted[4][4];
for(int i=0; i<4; i++) {
...
-2
votes
1
answer
73
views
printf in c printing extra charactors
I am new to stack overflow and c. Tell me if i need to add more details
I am trying to make a hangman game and when I try to print the board draw_board() Everything works except for printing the word ...