All Questions
8 questions
2
votes
0
answers
2k
views
How can I get the memory address of a global variable using a Format String Attack in C?
Code is here:
#include <stdio.h>
#define NUM 0x11a
int data = NUM;
int main(int argc, char * argv[])
{
struct{
unsigned long memoryAddress;
char array[50];
} locals;
...
1
vote
1
answer
153
views
Using " %c%c..." format specifier to print a string produces erratic results. Why is it so?
I am printing a string constant defined as a preprocessor directive using %s format specifier with printf() which produces the correct result.
But, then I tried some experimentation to see what will ...
3
votes
2
answers
624
views
What does $d do in printf?
I accidentaly wrote:
printf "here: %s $d\n" "${line:0:32}" "${#line}"
and got:
here: /home/gsamaras/Bash/libs/goodLib
here: 103
Why?
Of course I meant to say %d, but I don't understand this ...
1
vote
1
answer
4k
views
warning: field width specifier '*' expects argument of type 'int', but argument 2 has type 'size_t' {aka 'long unsigned int'}
Code:
#include <stdio.h>
#include <string.h>
int main(void) {
int number = 2;
printf("%*s\n", strlen("foo") + number, "foo");
return 0;
}
Warning:
prog.c: In function 'main':...
28
votes
5
answers
6k
views
What is the underlying difference between printf(s) and printf("%s", s)?
The question is plain and simple, s is a string, I suddenly got the idea to try to use printf(s) to see if it would work and I got a warning in one case and none in the other.
char* s = "abcdefghij\n"...
-3
votes
2
answers
208
views
How printf determine the content to be printed when a char pointer is passed with different format specifiers? [duplicate]
#include <stdio.h>
int main(void){
int a = 6;
int *pa;
pa = &a;
printf("%d\n",*pa); //6
printf("%d\n",pa); //1575619476
printf("%s\n",pa); //nothing, a empty line
...
-1
votes
1
answer
3k
views
how to use vasprintf() with special characters (%)? [duplicate]
I have the following sample code.
#include <stdio.h>
#include <unistd.h>
#include <stdarg.h>
int test(const char *fmt,...)
{
va_list args;
char *vacmd=NULL;
...
5
votes
3
answers
8k
views
%.#s format specifier in printf statement in c
Please explain the output. What does %.#s in printf() mean?
#include<stdio.h>
#include <stdlib.h>
int main(int argc,char*argv[]){
char *A="HELLO";
printf("%.#s %.2s\n",A,A);
...