Gets command error and gets_s command error [closed] - c

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I have just started to learn File I/O in C Programming. However, I tried to make my own project which is used to read a created file. Now that I have written my code below could you please find the error and tell me what is wrong. The compiler does not show any kind of error but also it won't run, the compiler just blinks and then quits.
I am using visual studio 2015 for my code:
#include <stdio.h>
int main(void)
{
FILE *fPointer;
fPointer=fopen("Database.txt","r");
char text[150];
while(!feof(fPointer))
{
fgets(text,150,fPointer);
puts(text);
}
fclose(fPointer);
return 0;
}

I'm guessing you have a Console project in Visual Studio, and you're running it by hitting the Debug button (green triangle) or F5. A black console window flashes briefly onto the screen and then vanishes.
This is normal. :-)
You are running your code, and it's finishing, and the console window that it runs in is going away when it quits.
To work around this "feature" of Visual Studio, put a breakpoint on the final return statement in main() (put the cursor on that line and press F9). Then the program will pause at that line, the console window will still be visible, and you'll be able to see your output.
(Alternatively, don't run it from within Visual Studio, but open a Command Prompt and run it from in there. But I'd advise against this, because running it in the debugger is so much more useful.)

Related

Obfuscated code in C and what does this program code [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 months ago.
Improve this question
I need help please about this obfuscated code, what does this do?, What methods or programs should I use to get conclusion?
If you can give me examples of obfuscating methods that were used by the author of the programs code, I would appreciate it.
It is really difficult to know what this code dose but I can say maybe for data security. Any one can help me with this code please.
#include <stdio.h>
#include <math.h>
#define E return
#define S for
char*J="LJFFF%7544x^H^XXHZZXHZ]]2#( ###DA#(.##%(0CAaIqDCI$IDEH%P#T#qL%PEaIpBJCA\
I%KBPBEP%CBPEaIqBAI%CAaIqBqDAI%U#PE%AAaIqBcDAI%ACaIaCqDCI%(aHCcIpBBH%E#aIqBAI%A\
AaIqB%AAaIqBEH%AAPBaIqB%PCDHxL%H#hIcBBI%E#qJBH#C##D%aIBI#D%E#QB2P#E#'C#qJBHqJBH\
%C#qJBH%AAaIqBAI%C#cJ%" "cJ" "CH%C#qJ%aIqB1I%PCDI`I%BAaICH%KH+#'JH+#KP*#%S#\
3P%H#ABhIaBBI%P#S#PC#", *j ,*e;typedef float x;x U(x a){E a<0?0:a>1?1:a; }
typedef struct{x c,a,t; } y;y W={1,1,1},Z={0,0,0},B[99],P,C,M,N,K,p,s,d,h
;y G(x t,x a,x c){K.c=t ; K.t=c; K.a=a;E K;}int T=-1,b=0,r,F=-111,(*m)(i\
nt)=putchar,X=40,z=5,o, a, c,t=0 ,n,R;y A(y a,y b,x c){E G(a.c+b.c*c,a.a
+c*b.a,b.t*c+a.t);}x H= .5,Y =.66 ,I,l=0,q,w,u,i,g;x O(y a,y b){E q=a.t*
b.t+b.c*a.c+a.a*b.a;}x Q(){E A(P,M,T ),O(K,K)<I?C=M,I=q:0;}y V(y a){E A(Z,
a,pow(O(a,a),-H));}x D(y p){S(I=X,P =p,b=T; M=B[++b],p=B[M.c+=8.8-l*.45,
++b],b<=r;Q())M=p.t?q =M_PI*H,w=atan2( P.a-M.a,P.c-M.c) /q,o=p.c-2,a=p.a+1,t=
o+a,w=q*(w>t+H*a?o: w>t?t:w<o-H*a?t :w<o?o:w),A( M,G(cos(w),sin(w),0),
1):A(M,p,U(O(A(P,M,T) ,p)/O(p,p))); M=P;M.a=- .9;o=P.c/8+8;o^=a=P.t
/8+8; M=Q ()?o&1 ?G(Y,0,0):W :G(Y,Y,1);E sqrt (I)-.45;}
int main( int L,char **k){ S(e =L>1?1[z= 0, k]:J ;*e &&l<24 ;
++e)S(o=a =0,j =J+9;(c= *++j)&& !(o&&c< X&&(q=l+=w) );o ?o=*j++/
32,b++[B] =G(q +=*j/8&3,* j&7,0 ),B[r =b++]=G((c/8& 3)*( o<2?
T:1), (c& 7)+ 1e-4,o>2),1: (o =(a =(c-=X)<0?w=c+6 ,t= a+1:c?(t
?0:m(c),a ):*++j)==((*e|32 ) ^z)&&1[j]-X));S(z =3*( L<3);++
F<110;)S(L=-301;p=Z,++L<300;m( p.c),m(p.a),m(p.t))S(c=T;++c<=z;)S(h
=G(-4,4.6,29),d=V(A(A(A(Z,V(G(5,0 ,2)),L+L+c/2),V(G(2,-73,0)),F+F+c%2),G
(30.75,-6,-75),20)),g=R=255-(n=z)*64; R*n+R;g*=H){S(u=i=R=0;!R&&94>(u+=i=D(h=
A(h,d,i)));R=i<.01);S(N=V(A(P,C, T)),q=d.t*d.t,s=M,u=1;++i<6*R;u-=
U(i/3-D(A(h,N,i/3)))/pow( 2,i));s=R?i=pow(U(O(N,V(A(
M=V(G(T,1,2)),d,T)))) ,X),p=A(p,W,g*i),u*=U(
O(N,M))*H*Y+Y,g*= n--?Y-Y*i:1-i,s:G(
q,q,1); p=A(p,s ,g*u);h=A(h,N,.1
);d=A(d,N,-2*O (d,N));}E 0;}
This is an obfuscated, miniature Raytracing program.
It is described on site https://mzucker.github.io/2016/08/03/miniray.html
I found it by taking part of the mystery string "LJFFF%7544x^H^XXHZZXHZ", and googling for it.
If you run the compiled program and capture the output, you get a raytraced picture in .PPM format:
a.out > output.ppm
When I tried to run the program using a Visual Studio / Microsoft toolchain, this is what I got:
When I ran the same program on Linux/GCC, I got this image:
A bit more work, and I got this out of it:
.\a.out abelenky > abelenky.ppm
One of pictures I posted above came via a Visual Studio / Microsoft toolchain, and has obvious corruption in the bottom third of the image, as well as the checkerboard being green (it is supposed to be red).
I ran the same code via GCC on Linux, and the images came out perfectly.
I'm not sure where the difference comes from, but this helps illustrate how obfuscated code like this can highlight differences between Toolchains, Compilers, Operating Systems, etc, and proves why code like this has value.
I'm really disappointed that "user129..." thinks this is of no use in programming. It is one of the most advanced, award winning, obfuscated programs ever written. The techniques used to both develop the program and to obfuscate it are discussed in some detail on the github page and linked resources. It stretches C and graphics algorithms to the limits in some amazing ways.
This should be preserved and studied. Not mocked and closed.

compile a C program that can run as admin without manual settings [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
okay~ i have searched for this question ,but the ans always solved C++ or C#
i want to fopen ("C:\\myfile.txt","w"); it will permission denied .
how can i compile a C program can run as admin without any manual setting?
i'm using wxDEV-C++ 7.4.2.
any ideas ?
/* fopen example */
#include <stdio.h>
int main ()
{
FILE * pFile;
pFile = fopen ("C:\\myfile.txt","w");
if (pFile!=NULL)
{
fputs ("fopen example",pFile);
fclose (pFile);
}
return 0;
}
first , thx lurker fixed my poor English title . its a big help.
sec, what i mean is a program can trigger UAC pop out ,then user can just give a single click to agree to run as admin,so user won't need to right click run as admin.
thx SoronelHaetir had solve my question .
If you want your program to run as admin without needing to do the right click and select run as administrator you will need to embed a manifest that tells the OS to run your program with administrator credentials. This will still pop up the UAC window asking the user if they want to allow the program to run.
You can read about the application manifest format at https://msdn.microsoft.com/en-us/library/aa374191(v=vs.85).aspx
This is simply not possible without being a hacker and utilizing weaknesses in the OS. The whole point of permission handling is that a program should not be able to decide that it should be run as admin.

How do I prevent the console (application file) from closing itself immediately after running in windows? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
After I compile my program and run the executable, it closes instantaneously. I barely see my output. How do I prevent this?
The following two lines will print the message "Press ENTER key to Continue" and then pause execution waiting for the enter key. I hope this helps.
printf("Press ENTER key to Continue\n");
getchar();
The problem is quite common when starting to learn C/C++..
the reason is that console applications once finisher return from their main method, the associated console window automatically closes. This behavior has nothing to do with what your app does or not, or if the app is working well or not.
To "correct" this simple add a pause just before the return statement in the main method
Example:
....
system("pause");
return 0;
}
Try to run it natively through the cmd.
Let's say that your file is in C:\file.exe
Open the cmd, type cd C:\ and then type file.exe
Try to add system("pause"); to your program to keep it opened.
like below:
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
printf("Hello world!");
system("pause");
return 0;
}
Do this
int main()
{
// your code
system("pause"); // this will stop the pause
return 0;
}

How do I run a C program from my Windows command prompt? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Using Vim as an editor, I wrote the following simple code in C and saved it as helloworld.c :
#include <stdio.h>
int main(void)
{
printf("Hello world!\n");
}
In command prompt, I wrote:
start chrome helloworld.c
This caused my browser to open up the file, but it did not print Hello World. Instead, it just displayed the code I had written. Did I not save it as a C file?
Also, I was wondering how to display the result of my C program inline on command prompt, as I am fairly new to it. While searching the internet, I could not find any answers. Am I supposed to do so from Vim? I learned that you are supposed to do ./ in the gedit command box to display the result inline, but this does not work for the one that comes with Windows.
Please help and thank you for taking the time to read and answer.
As #Ernest Friedman-Hill has already said, you normally have to compile the program. However, there are alternatives.
One alternative is the Tiny C Compiler, from http://bellard.org/tcc/. TCC does allow you to run the program without compiling it.
tcc -run helloworld.c
Does exactly what you want.
The Tiny C Compiler is not the only way to run C code from source without compiling it first. There are a few other alternatives.
CSL: http://csl.sourceforge.net/csl.html
Ch: https://www.softintegration.com/
PicoC: https://code.google.com/p/picoc/
CINT: http://root.cern.ch/drupal/content/cint
I hope this helps.

opening an .exe after using Mingw

I followed the instructions in this video:(See Docs)
What happened is that I created a very basic program in C, here is the code:
#include <stdio.h>
int main()
{
printf("Hey Buddy!\n");
return 0;
}
I compiled it using Mingw and an .exe file was created. Here the problem begins...
When simply opening the file in windows, a cmd window that says "Hey Buddy!" opens and closes immediately.
When trying to run the .exe file using the command line, the same thing happens, but the command line window then becomes stuck and it is impossible to close it - only shutting off the computer can do it.
Your help would be very appreciated, and I am sorry if I am doing something dumb and not realizing it:)
Your program is fine. The main declaration is wrong. It should be
int main(void)
but the declaration in your question won't cause any problems. I'm just telling you this to set you off on the right path.
Of course when you double click on the executable, then a new console window appears and immediately disappears. The program prints a single line of text and returns immediately. That behaviour is as expected.
The problem with the console window that cannot be closed is not down to an error in your code, at least the code that is shown in the question cannot explain that. That is presumably an environmental problem with your machine and/or compiler installation. Or perhaps you just have not yet worked out how to close a console window.

Resources