I have readed a lot of people with the same problem but the most of them are Windows Defender, in my case it only happens with avast(free version) and it detects this simple hello program compiled version:
#include <stdio.h>
int main()
{
printf("Name: ");
char name[20];
scanf("%s", name);
printf("Hello, %s\n", name);
return 0;
}
as "Win32:TrojanX-gen[Trj]" but some days ago i made another program and ran it into notepad++ console using cmd and nothing happened, is it a problem with avast or is it my pc?
Thank you.
Related
So basically, I have this simple Hello World program and when executed, it outputs correctly.
#include <stdio.h>
int main(){
printf("Hello");
}
Output: Hello
But for some reason adding a scanf command will cause the program to not output anything. It will display that it's running but it won't display anything.
#include <stdio.h>
int num1;
int main(){
printf("Enter number: \n");
scanf("%d", &num1);
printf("%d", num1);
}
Output:
[Running] cd "d:\programming\" && gcc main.c -o main && "d:\programming\"main
I know my code is okay since I tried it on other IDEs and it worked correctly. I even copied code from the internet and tried to run in VSCode but it still didn't work. It still works perfectly fine yesterday but this problem just pops in nowhere.
I use Visual Studio Code 1.62.3 with C/C++, C/C++ Compile Run, and Code Runner extensions.
It's a buffering problem. When standard output (stdout, where printf writes) is connected to an actual terminal then it's line-buffered, which means output is actually written to the terminal when there's a newline.
However, VSCode probably uses its own terminal emulation and uses pipes to connect stdout to that terminal. That means the output will be fully buffered, and you need to explicitly flush it.
So modify the code as such:
printf("Enter number: \n");
fflush(stdout); // Actually write the output to standard output
scanf("%d", &num1);
printf("%d", num1);
That it works for the first example is because then the process terminates, and all output is flushed automatically.
I've written a simple C program:
#include <stdio.h>
int main(void){
char first[20];
char last[20];
printf("Enter first name: ");
scanf("%s", first);
printf("Enter last name: ");
scanf("%s", last);
printf("Hello %c %c. \n", first, last);
return 0;
}
Then I built the program with compiler from GCC using gcc.exe build active file command and debugged it with the GDB configuration. There is no output in the debug console unless I set 'externalConsole' = true in launch.json, however if I do so I will not be able to examine if my program works or not, because the console window closes immediately after I have entered the strings.
How should I solve this problem and make sure I can debug the program properly?
As you will see I am not good in c programming, still learning but my WindowsDefender is yelling at me for compiling this code with MinGW from Codeblocks IDE.
#include <stdio.h>
#include <string.h>
int main(void){
char *strings[] = {"test", "test"};
char *newStr;
int i;
for(i=0;i<2;i++){
strcat(newStr, strings[i]);
printf("%s\n", newStr);
}
return 0;
}
Can you help me with that I don't know what this is about. This can't be a normal issue mh?
I have been having this for several days recently when I compile simple programs in C in Microsoft Visual Studio 2019 Community edition. For example this one.
#include <stdio.h>
int main() {
int a = 10;
for (int i = 0; i < 5; i++) {
a--;
printf("i = %d\n", i);
if (a == 8) break;
}
}
The problem isn't with your program (or mine) but Windows Defender has become overly paranoid and is erroneously identifying normal compiled code. I get the same Trojan warning as you. The danger is if we turn off Defender for crying wolf that a real virus could slip onto an unguarded Pc. I'm tempted to switch to a different a/v like AVG or switch into hyper-V and compile programs on Ubuntu with GCC or clang.
I have written a program in Bloodshed using the C language for homework, but after clicking compile and run, I get an error message saying: Source file not compiled. I have ran compile only with it telling me that it's done, but when I compile and run afterwards, I get the same previous error message. How do I fix this? I am using windows 10 and here is the program:
/*TECH 1211 Computer Programming */
/*Mark Bowman */
/*Program Name "Formatted Output of Table" */
/*Spring 2019 */
#include<stdio.h>
#include<stdlib.h>
int main (void) {
printf("Mark Bowman\n\n");
char airline;
printf("Enter the first letter of the airline:");
scanf("%c",&airline);
int airline_number;
printf("Enter the flight number:");
scanf("%d",&airline_number);
int hour,minute;
char time_of_day;
printf("Enter the departure time as (hh:mm)");
scanf("%d:%d %c",&hour,&minute,&time_of_day);
float ticket_price;
printf("Enter the ticket price:");
scanf("%f",&ticket_price);
printf("\n\n\nAirline Flight\tDeparture\tTicket\n\t\tNumber\tTime\tPrice\n\t %c %d\t%d:%d %cm\t$%.2f\n\n\n--------------------------",airline,airline_number,hour,minute,time_of_day,ticket_price);
return(0);
}
I just came across this issue and it turns out Bloodshed Dev C++ is not compatible with Windows 10. It didn't even detect any errors during compilation if I intentionally added them.
Fortunatelly, there's this open source project called Embarcadero Dev-Cpp which is a port to Windows 10, they even have a portable version that works very well.
I have installed MinGW on netbeans for C and C++ programming.
Here is a simple code that I am trying to run on netbeans :
#include <stdio.h>
int main(int argc, char** argv) {
printf("Inside Main...\n");
int n;
printf("Enter : ");
scanf("%d", &n); // When I remove this line, it is working.
printf("You have entered %d.", n);
return (1);
}
Whenever I try to access any value from netbeans console, I don't see anything.
Output with scanf(...)
Output without scanf(...)
And if I try to run these code from cmd, all are working
for scanf() you must use Netbeans External Terminal !
Normal Run
You can also use Netbeans Standard Output !
But this is more misleading.
While you see an empty Terminal do input 123
after hit enter , you get the output all at once .
I had the same issue while running a CPP program.External output didn't helped me. I set the console type to Standard output and it solved the issue.
Right Click cpp Application-->properties-->run--->Consoletype to standard output