logo
down
shadow

second printf not working when using a variable C-programming


second printf not working when using a variable C-programming

By : gamingbookwyrm
Date : November 20 2020, 03:01 PM
wish of those help You have to pass the pointer of a to scanf and remove \n from scanf. If you want to go on a new line add \n before your number is...
The code becomes like that
code :
#include<stdio.h>
int main(void)
{
    int a;
    printf("enter your number\n");
    scanf("%d", &a);
    printf("\nyour number is %d\n", a);
}


Share : facebook icon twitter icon
Why can printf() resolve the variable name to access the value stored in it but scanf() cannot (in C programming)?

Why can printf() resolve the variable name to access the value stored in it but scanf() cannot (in C programming)?


By : Jules
Date : March 29 2020, 07:55 AM
wish helps you scanf() needs a pointer as argument but printf doesn't. printf just needs the variable's name and it somehow seems to obtain the value stored in the memory location of the variable. Why wasn't scanf made to behave in the same way by resolving the variable name into the memory location (the same way printf works) and storing the value in it? , C is a pass-by-value language. If you were to write:
code :
int x;
scanf("%d", x);
scanf("%d", &x);
int *y = &x;
scanf("%d", y);
printf("%d", x);
c programming, why printf does not working?

c programming, why printf does not working?


By : Adam Putterman
Date : March 29 2020, 07:55 AM
Does that help , This:
code :
arr[3]=arr[0]-arr[1];
printf("[%c] %d\n", op, arr[3]);
arr[2] = arr[0] - arr[1];
printf("[%c],  %d\n", op, arr[2]);
printf won't print a variable in Cygwin, though working on Mac OS Terminal

printf won't print a variable in Cygwin, though working on Mac OS Terminal


By : Hüseyin BAŞARAN
Date : March 29 2020, 07:55 AM
I hope this helps . The problem is due to the nonprinting carriage return character (sometimes represented as \r or ^M or ). DOS and Windows use the convention that lines of text are terminated with a carriage return followed by a linefeed, but unix just uses a linefeed. As a result, when you take a DOS/Windows-format line and hand it to a unix program (e.g. the shell), it thinks the linefeed is the end of the line, and treats the carriage return as part of the content of the line. This problem happens a lot when using unix tools in Windows (e.g. Cygwin).
In this case, I assumed it was because the script file itself was in DOS/Windows format, but apparently not; so I'm not sure exactly where the carriage return is coming from (perhaps perl is trying to be Windows-compatible and outputting DOS/Windows format?). Anyway, the net result is that the variable bitrate has a carriage return at the end. Printing it by itself, this isn't visible, but if you print it followed by a space and the filename, it sends "31103 kb/s\r 20180305-01.mov" to the terminal, which prints "31103 kb/s", then the carriage return makes it go back to the beginning of the line (that's actually what "carriage return" means"), then it prints " 20180305-01.mov" over top of the "31103 kb/s", replacing it.
code :
$ printf 'the var is %q\n' "$bitratenormal"
the var is 31103\ kb/s
$ printf 'the var is %q\n' "$bitratewithcr"
the var is $'31103 kb/s\r'
$ cat filewithweirdchars 
This line is normal
This line ends with a space 
This line ends with a tab   
This line ends with a carriage return
This line has nonbreaking spaces and “weird” unicode quotes
$ LC_ALL=C cat -vet filewithweirdchars 
This line is normal$
This line ends with a space $
This line ends with a tab^I$
This line ends with a carriage return^M$
ThisM-BM- lineM-BM- hasM-BM- nonbreakingM-BM- spaces and M-bM-^@M-^\weirdM-bM-^@M-^] unicode quotes$
Initializing a variable causing printf to stop working

Initializing a variable causing printf to stop working


By : manju Mahandule
Date : March 29 2020, 07:55 AM
To fix this issue If you want to use atoi on a char array, you must put a null terminator at the end. Adding things to the stack changing the behaviour often means you have walked off the end of some memory. Make str bigger and add the null at the end:
UDP Socket Programming in C, printf not working after calling recvfrom()?

UDP Socket Programming in C, printf not working after calling recvfrom()?


By : akhila kota
Date : March 29 2020, 07:55 AM
Any of those help I am working on a project regarding socket programming in c and java, using UDP and TCP (separately of course). My UDP server is Java and my UDP client is in C. I have encountered an issue where, after I call recvfrom(), methods such as printf and fprintf are not actually printing everything. I also tried fflush. Here is that section of code: , Usual problem. You're ignoring the count returned by recvfrom():
code :
printf("%.*s\n", strlen(buf), buf);
printf("%.*s\n", n, buf);
n = recvfrom(sockfd, buf, sizeof buf, 0, (struct sockaddr *)&serveraddr, 
  &serverlen);
Related Posts Related Posts :
  • Casting the sum of some variables to a pointer and then to an integer again
  • What's the easiest way to send 802.11 frames using C?
  • C Opening a file to check if it is Binary, if so print it is binary
  • why 2 different strings have the same address in C?
  • when I try to end an event controlled loop in c it takes two inputs?
  • adding string to character array at specific position giving buffer overflow in c programming
  • C - Separating string using other delimiters?
  • Rounding down a floating point number to an integer value without a floor function in C
  • Why does the computer ignore my program?
  • Pointer calculation in Linux Kernel allocation implementation
  • conflicting types for s32_t in c code for STM32F7xx
  • Getting error in AVL tree
  • LD_PRELOAD and linkage
  • For loop skipping numbers in C
  • C code - Why the output returned unexpected value in my code?
  • C - can variate location be promoted?
  • Signal SIGSEGV recieved: vfprintf.c: No such file or directory?
  • Does Posix thread ID have an one-to-one relation with linux thread ID?
  • C - fgets doesnt wait for input when initializing pointer
  • I cannot perform data validation on my four arrays properly.
  • How do I fix this segmentation fault in my c code
  • How to use pointer to split the string into two strings? C language
  • Knuth List Insertion Method in C
  • Tons of error in Visual Studio 2017 with GetUserNameEx at compile time
  • Invalid conversion of char to float, different codes and no good results
  • Why doesn't my code for checking if a word is a palindrome work?
  • My program compiles and when ran, it doesn't give me the input i put in
  • How to find if a graph contains a cycle using a recursive DFS?
  • Memory mapped file cannot be closed without un-mapping, since it's still referenced
  • Why is this simple program giving me seemingly incorrect output?
  • Shared memory variable in c
  • Linked List and Pointers in C
  • Counting Character usage in text file? C
  • C: Why does assigning a 2D array of ints to an int** cause CLION to highlight the line?
  • How does fwrite work?
  • Why is my http server printing out the same bytes? (C)
  • The following code doesn't stop looping
  • Strcmp gives segmentation Fault
  • Segmentation fault: 1902 vfscanf.c: No such file or directory
  • Mutex - counting occurrences of a char in files using threads
  • Returning arrays in C instead of switch statements, nested set of values
  • Trying to pass addresses to simple variables to a function (pointers & loops) In C
  • Recursively list directories in C on Linux
  • Math operation in the test expression of the `for` loop - perfomance, optimisation
  • what is the difference between extern char **environ and extern char *environ[]
  • Is it possible to bind a socket to 2 adresses in c?
  • error when compiling testfiles from installed c-algorithms library
  • Count alternating up / down sequences
  • ISR documentation with doxygen
  • How to solve the sum of three digit numbers,with how to calculate the second number
  • Recursion C image compressor algorithm
  • Unix system programming: get a network identifier to be passed to getaddrinfo
  • misaligned address access crash on linux wifi drivers on arc platform
  • Having a character appear repeated times in an array and score counts.
  • Given a number A(=2^N), how to get the N?
  • Reading Hex from an file
  • Realloc affecting fgets
  • Run C server and client files in CLion at the same time
  • How to check last character in command line arguements?
  • How to seperate user input word delimiter as space using strtok
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org