#include <stdio.h>
int main(){
printf("asd");
return 0;
}
The task is without modifying this program, overwriting or using define, in windows environment, this program have to write out : Yourname asd Yourname. Any idea?
You can do it like this (edited to read Yourname from stdin):
#include <stdio.h>
#include <string.h>
int main(){
printf("asd");
return 0;
}
int printf(const char *__restrict __format, ...)
{
char str[106], scs[50];
scanf("%s", &scs);
strcpy(str,scs);
puts(strcat(strcat(strcat(strcat(str," "), __format)," "),scs));
return 1;
}
Here's a working demo.
printf, in the context of the one definition rule (as your linked answer in the comment does).malloc ;) I'm not sure about the inner workings though...You can do it in a simple way. Global objects are created on the static memory area, they are allocated and initialized before the execution of main, and are freed after the execution of main. Here's the simple answer to your problem:
#include<iostream>
struct MyName {
public:
MyName() { printf("%s", "GaborRuszcsak\n"); }
~MyName() { printf("%s", "\nGaborRuszcsak\n"); }
};
MyName isGaborRuszcsak;
int main(int argc, char** argv){
printf("asd");
return 0;
}
Hope that helps.
#include <stdio.h>).
printfasmallocwas redefined in this answer.