Skip to main content

All 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; ...
Gardas462's user avatar
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 ...
Viper's user avatar
  • 13
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 ...
gsamaras's user avatar
  • 73.5k
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':...
gsamaras's user avatar
  • 73.5k
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"...
Mikael's user avatar
  • 989
-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 ...
Albert Gao's user avatar
  • 3,789
-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; ...
avishkar's user avatar
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); ...
silentseeker's user avatar