Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pointless macro letting you change number of characters read by scanf depending on the N value #475

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -491,3 +491,8 @@ Name: [antoooks](https://github.com/antoooks) </br>
Place: Indonesia / Singapore </br>
Coding Experience: JS, TS, PHP, Java, Go. Specialize in CI/CD, Cloud Architecture, and Automation.
Email: [email protected] </br>

Name: [shaxi1](https://github.com/shaxi1) </br>
Place: Poland </br>
Coding Experience: C, Cpp, Python, JS </br>

17 changes: 17 additions & 0 deletions c/shaxi1_macro.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <stdio.h>
// number of wanted characters in string
#define N 100
#define str(s) #s
#define xstr(s) str(s)

int main() {char arr[N+1];printf("Type something\n> ");scanf("%"xstr(N)"[^\n]", arr);printf("%s\n", arr);return 0;}

/* gcc -E macro.c | how macro looks "pasted" into code
int main() {
char arr[100 +1];
printf("Type something\n> ");
scanf("%""100""[^\n]", arr);
printf("%s\n", arr);
return 0;
}
*/