0 Members and 1 Guest are viewing this topic.
#include <stdio.h>#define IN 1 /* inside a word */#define OUT 0 /* outside a word *//* count lines, words, and characters in input */main(){ int c, nl, nw, nc, state; state = OUT; nl = nw = nc = 0; while ((c = getchar()) != EOF) { ++nc; if (c == '\n') ++nl; if (c == ' ' || c == '\n' || c == '\t') state = OUT; else if (state == OUT) { state = IN; ++nw; } } printf("%d %d %d\n", nl, nw, nc);}
the code there
Code: [Select]#include <stdio.h>#define IN 1 /* inside a word */#define OUT 0 /* outside a word *//* count lines, words, and characters in input */main(){ int c, nl, nw, nc, state; state = OUT; nl = nw = nc = 0; while ((c = getchar()) != EOF) { ++nc; if (c == '\n') ++nl; if (c == ' ' || c == '\n' || c == '\t') state = OUT; else if (state == OUT) { state = IN; ++nw; } } printf("%d %d %d\n", nl, nw, nc);}
while ((c = getchar()) != EOF)
myapplication < example.txt
What do you mean?
if (c == ' ' || c == '\n' || c = '\t')
ds dude: if you want to program in C seriously, get linux. It is far easier.
oh no, sorry It's a command-line, that means you'll have to 'run' it like that. You can do that by going to the start menu and select run and then filling in the complete path to your own .exe plus the extra command '< example.txt'.Another way is using Command Prompt, you'll have to read how to work in it (it's old DOS), but if you want to learn how to program on Windows, that's not a bad idea.A bit easier way would be to make a small batch-file. Batch-files will run command-lines for you and are easily made. Just create a new text-file and fill in:Code: [Select]myapplication < example.txtreplace 'myapplication' with the name of your .exe file. Then save this file in the same directory as your application. The name of this file doesn't matter, but make sure it ends with .bat and not .txt! If you double-click that file it will run the command line and your program will be loaded together with the example.txt file. Of course you also have to make example.txt
ds dude: if you want to program in C seriously, get linux. It is far easier.I'd also suggest not using an IDE when learning it. It may seem easier but learning to write makefiles (easy to do) and link stuff by hand and such are very useful skills. And way easier on linux.Quote from: ds dude on March 25, 2009, 01:52:21 pmif (c == ' ' || c == '\n' || c = '\t')That is a really common error (among new people, when you get better you get to start messing up with pointers yay!) because it doesn't give an error when you compile it and run it. This is partly why I like Java as a first programming language, you save a LOT of time that would normally be spent debugging, and you can learn the programming concepts easier.If you want a good C book btw, C for Dummies by Dan Gookin is actually really good.
Quote from: iDante on March 25, 2009, 05:03:37 pmds dude: if you want to program in C seriously, get linux. It is far easier.Highly recommend Linux.I think it's cool your pursuing C. I have never gotten around to be competent with it, but out of all languages it is probably to learn because the concepts is has are similar to ones in many other languages. Good luck bud.
I need to find a good and easy way to put a persistent ubuntu on a usb and program from there. I'll have to figure out how to compile my program to what Linux can execute from, because EXE is out of the question. Any help with this is greatly appreciated. Btw, I'll look into that book. Thanks.
Yes, jrgp showed me the light and help me with getting a compiler running and using Visual C++ (which I save all my code in C source file), which reminds me, what does Linux use to code with?
//Sets where the bot looks and moves to.var ID;ID=0if bot_check_ground(x+image_xscale*25,y,x+image_xscale*25,y+600)=false{ if place_free(tar_x,tar_y) { tar_x=x+lengthdir_x(50,point_direction(x,y,room_width/2,y)) tar_y=y aim_tar_x = tar_x; aim_tar_y = tar_y; } if image_xscale=1 { move_dir="left" }if image_xscale=-1 { move_dir="right" }}else{ if instance_exists(o_w_healing) { ID=instance_nearest(x,y,o_w_healing) } var xx, yy; xx=room_width/2 yy=-2000 if instance_exists(ID) { xx=ID.x yy=ID.y } if (life<20 and distance_to_point(xx,yy)<900) or (life<100 and !instance_exists(tar)) and instance_exists(o_w_healing) and distance_to_object(ID)<800 { bot_find_object(instance_nearest(x,y,o_w_healing)) } else { if distance_to_object(o_bomb)<100 //Avoid grenades { ID=instance_nearest(x,y,o_bomb) if distance_to_object(ID)<200 { tar_x=x+lengthdir_x(-230,point_direction(x,y,ID.x+ID.hspeed*10,ID.y+ID.vspeed*10)) tar_y=y+lengthdir_y(-230,point_direction(x,y,ID.x+ID.hspeed*10,ID.y+ID.vspeed*10)) aim_tar_x=x+lengthdir_x(-230,point_direction(x,y,ID.x+ID.hspeed*10,ID.y+ID.vspeed*10)) aim_tar_y=y+lengthdir_y(-230,point_direction(x,y,ID.x+ID.hspeed*10,ID.y+ID.vspeed*10)) } } else { { if instance_exists(lkl) { ID=instance_nearest_ext(x,y,lkl,1) if distance_to_point(ID.x,ID.y)<1000 and collision_line(x,y,ID.x,ID.y,o_solidparent,0,true)<0 { tar_x=x+lengthdir_x(-300,point_direction(x,y,ID.x,ID.y)) tar_y=y-40+lengthdir_y(-50,point_direction(x,y,ID.x,ID.y)) aim_tar_x = x+lengthdir_x(-300,point_direction(x,y,ID.x,ID.y)) aim_tar_y = y-40+lengthdir_y(-50,point_direction(x,y,ID.x,ID.y)) if !(place_free(tar_x,tar_y)) { tar_y-=100 } } else { bot_idle() } if global.mode=0{bot_chase_2()} } }}}}