2,384 Posted Topics

Member Avatar for kohkohkoh

In C,[code]#include <stdio.h> int main(void) { char filename[256], name[] = "Derrick"; FILE *file; [COLOR=Blue]sprintf(filename, "%s.txt", name);[/COLOR] file = fopen(filename, "w"); if ( file != NULL ) { [COLOR=Blue]fprintf(file, "%s\n", name);[/COLOR] fclose(file); } return 0; }[/code]

Member Avatar for DoEds
0
129
Member Avatar for spursfan2110

[QUOTE=spursfan2110;1141256]Here's the pertinent part of code:[/QUOTE] Do yourself and everyone else a big favor: post [B]actual[/B] code, not a "pertinent" version. You already demonstrated that you introduce separate errors in doing so. Trim your code into a separate, smaller snippet if you choose. But post actual code that compiles and …

Member Avatar for Dave Sinkula
0
187
Member Avatar for nsjoe

[QUOTE=nsjoe;1141036]This is probably a simple fix but I can't quite figure it out. How can I find an escaped character in in a string? E.g. string str = "abcde\tfghi"; [CODE] while (str [counter] != '\t') { counter++; } [/CODE][/QUOTE] [QUOTE=WaltP;1141046]Didn't that work?[/QUOTE] [QUOTE=nsjoe;1141050]No, it's reading the backslash and 't' as …

Member Avatar for Dave Sinkula
0
143
Member Avatar for Notme

[QUOTE=Notme;1141011]basically what im trying to do is remove all * !"£$%^&*()- and double spaces from a text file[/QUOTE] You could write your own iswhatever() type of function -- a linear search through [iCODE]"*!"£$%^&*()-"[/iCODE] would find these. You might also look into ispunct(). The double-spaces would be a little extra.

Member Avatar for Dave Sinkula
0
1K
Member Avatar for Encrypted

[QUOTE=CodeEgg;1140490]In any case, that strcmp is not working properly either.[/QUOTE] Post your actual code containing all of your latest attempt. Trying to piece together what incremental changes you may or may not have made makes it more difficult for you and everybody else. Odds are strcmp is working just fine; …

Member Avatar for Dave Sinkula
0
137
Member Avatar for riotburn

[QUOTE=riotburn;1130662]What do you mean by hanging?[/QUOTE] [QUOTE=Narue;1130659]Just because it compiles without errors doesn't mean the code works. Your I_simpson function is hanging, [COLOR="Red"]which means it doesn't return, which means you don't get any output.[/COLOR][/QUOTE] :icon_lol:

Member Avatar for jazz_vill
0
420
Member Avatar for Encrypted
Member Avatar for corby

[QUOTE=chunalt787;1139200]I know this is a few days old but heres a good tutorial I like to show my intro students. Hope it helps. [url]http://coutblog.com/?p=5[/url][/QUOTE] Meh. [QUOTE]A pointer, unlike a variable, is actually an address.[/QUOTE] A pointer [I]variable[/I] is certainly a variable. [QUOTE]sizeof(char) returns the size of a char(typically 1 byte)[/QUOTE] …

Member Avatar for Dave Sinkula
0
179
Member Avatar for doddware

Equivalent statements should not be different in efficiency. (And I'd avoid the premature optimization thing here anyway.) [I][[URL="http://cboard.cprogramming.com/cplusplus-programming/85047-guess-code-7.html"]Footnote[/URL]: I find the !! easier to understand than its equivalent. Just part of the code I saw while learning, I guess, for better for worse.][/I]

Member Avatar for Salem
0
185
Member Avatar for ShortYute

[B][url]http://predef.sourceforge.net/precomp.html[/url][/B] [url]http://predef.sourceforge.net/preos.html[/url] [url]http://predef.sourceforge.net/prestd.html[/url] [url]http://predef.sourceforge.net/prelib.html[/url] [url]http://predef.sourceforge.net/prearch.html[/url] [edit][B][url=http://predef.sourceforge.net/precomp.html#sec3]Borland C++[/url][/B], [B][url=http://predef.sourceforge.net/precomp.html#sec31]MinGW[/url][/B]

Member Avatar for Salem
0
182
Member Avatar for kangarooblood

[QUOTE=kangarooblood;1138635]well i do not want to use the system syntax, isn't there any other way to open a program in c++?[/QUOTE] [url=http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1044654269&id=1043284392]FAQ > How do I... (Level 2) > Run a program from within a program[/url]

Member Avatar for Ancient Dragon
0
115
Member Avatar for COKEDUDE

My preference for user input: [url]http://www.daniweb.com/tutorials/tutorial45806.html[/url]

Member Avatar for Dave Sinkula
0
130
Member Avatar for Morrac

You're new and you're messing with atexit? Why? [edit]The argument passed to [URL="http://linux.die.net/man/3/atexit"]atexit[/URL] is: [CODE]int atexit([COLOR="Red"]void (*function)(void)[/COLOR]);[/CODE] [edit=2]And that oneargument/twoargument function stuff -- are you going out of your way to over-complicate things?

Member Avatar for Morrac
0
113
Member Avatar for COKEDUDE

[QUOTE=xavier666;1129774]I still have to come across this error[/QUOTE] I run into it constantly. My preferred IDE is SlickEdit (on Windows). When I build and execute the code, SE runs it in a shell. This environment in which the code is run (the important part here) does not display the prompt. …

Member Avatar for sumitunya
0
2K
Member Avatar for abhimanipal
Member Avatar for johndoe444

Try to create a minimal snippet that is compilable and demonstrates the issue.

Member Avatar for johndoe444
0
137
Member Avatar for kendaop

Nit: that's not really demonstrating "what happens when you cast an unsigned long to unsigned char"; it's actually examining the bytes composing the unsigned long value. Close, but I'm having a bit of a pedantic moment. [CODE]#include <stdio.h> int main(void) { unsigned long value = 0x01234567UL; unsigned char byte = …

Member Avatar for Dave Sinkula
0
5K
Member Avatar for goldenmean

[QUOTE=goldenmean;1135839]3.)Is there any other tool (free/commercial license)which can detecl memory leaks, array out of bound errors, use of uninitialized pointers, variables, memory corruption etc.. by doing run time analysis of C code.[/QUOTE] PC-lint does many of the things you mention, but as static analysis and not as run-time. A sample …

Member Avatar for Dave Sinkula
0
287
Member Avatar for darkagn

[QUOTE=cscgal;1127049]The whole purpose is to arm forum lurkers with a mechanism to rate posts in a way that is more anonymous than reputation.[/QUOTE] It rather works like crap, though. Let's say someone has a great post and gets 1 or 2 upvotes. Then some idiot comes along and says something …

Member Avatar for Ancient Dragon
0
469
Member Avatar for moein_soltani

Here are some things to consider looking into: [QUOTE]--- Module: main.cpp (C++) main.cpp 38 error 1551: (Warning -- Function may throw exception '...' in destructor 'Huffman::~Huffman(void)') main.cpp 39 error 1540: (Warning -- Pointer member 'Huffman::codes_list' (line 69) neither freed nor zeroed by destructor) main.cpp 69 error 830: (Info -- Location …

Member Avatar for moein_soltani
0
2K
Member Avatar for sk8ndestroy14

[QUOTE=sk8ndestroy14;396191]This thread is about John F. Kennedy's assassination. Talk about anything relating to it like the single bullet theory etc. or talk about who was behind the assassination. Anything about it. Feel free to go off on some crazy rant if you want.[/QUOTE]I like this subject. I liked the movie. …

Member Avatar for brandonyy4u
0
741
Member Avatar for free2rhyme2k
Member Avatar for johndoe444
Member Avatar for Dave Sinkula
0
94
Member Avatar for techno_weenie

Some lint: [QUOTE]--- Module: main.c (C++) main.c 3 error 537: (Warning -- Repeated include file 'D:\Programs\CodeBlocks\MinGW\lib\gcc\mingw32\3.4.5\install-tools\include\stddef.h') main.c 16 error 1776: (Info -- Converting a string literal to char * is not const safe (initialization)) main.c 39 error 527: (Warning -- Unreachable code at token 'if') main.c 96 error 530: (Warning …

Member Avatar for techno_weenie
0
197
Member Avatar for bp2005

[QUOTE=bp2005;1133804]This works, except if I later change the contents of myVariable. I guess it might be wrong to declare it as a const in the first place, but that's what the function demands. I'm a bit lost with this right now, so any help/guidance will be appreciated.[/QUOTE] How is it …

Member Avatar for bp2005
0
98
Member Avatar for techno_weenie

An idea: [CODE]#include <stdio.h> int main() { char result[] = "/usr/bin/ssh \n" " * \n" " 147.188.195.15, 147.188.193.15, 147.188.193.16 \n" " 22"; char programnames[256], uids[256], destips[256], ports[256]; if ( sscanf(result, "%255[^\n] %255[^\n] %255[^\n] %255[^\n]", programnames, uids, destips, ports) == 4 ) { printf("programnames = \"%s\"\n", programnames); printf("uids = \"%s\"\n", uids); …

Member Avatar for jephthah
0
144
Member Avatar for sahiti
Re: C

[QUOTE=sahiti;1132566]hey wat is d use of gets( ) function in C..?:?:[/QUOTE][LIST] [*]It's an unsafe function that should never be used. [*]When found in code, its presence prompts more experienced programmers (those with more than say, 1 day of C programming under their belts) to pound on the pathetic, poor, foolish …

Member Avatar for Dave Sinkula
-5
138
Member Avatar for chriselda

[QUOTE=Iam3R;1131434][CODE] char str[]="the quick brown fox and the lazy dog" ; int i =0; while(str[i] !=' ' ) i++; strcpy(str,str+i+1); [/CODE] works if the above is your requirement, analyze it yourself. happy learning...........[/QUOTE] Spot the undefined behavior in the above code. Happy learning! ;)

Member Avatar for Dave Sinkula
0
115
Member Avatar for klactose

I can't get the posted code to build (so I therefore don't have much to say about its runtime behavior), and I'm too lazy to try to fix it. Here are some warnings you might want to look into: [QUOTE]main.c: In function `getString': main.c:108: warning: no return statement in function …

Member Avatar for gerard4143
0
174
Member Avatar for adrawat

[QUOTE=adcodingmaster;1129626]As you can see that he has appriciated my answer by saying "Thanks 4 that garbage char prob".[/QUOTE] I thought his reply was to Salem. [QUOTE=Salem;1129476]> the output file will have no characters if the input file has no characters. i = 0; After the first loop of NO characters, …

Member Avatar for adrawat
0
399
Member Avatar for MrYrm
Member Avatar for Stefano Mtangoo
0
122
Member Avatar for COKEDUDE

[QUOTE=COKEDUDE;1130928]When I put "return 1" in a few of my programs it stopped execution of the rest of my program. [/QUOTE] Returning from a generic function, or returning from main? Returning from main means your program is "done".

Member Avatar for WaltP
0
255
Member Avatar for mswezey
Member Avatar for rmrgrs

Headers are important, don't remove them. Just post actual code. [CODE]GetTemperatures(int HourlyTemperatures[])[/CODE] What's the return type? And you call this function without a prototype.

Member Avatar for rmrgrs
0
84
Member Avatar for Dewey1040

The end of s1 will be where s1[i] == '\0'. The end of s2 will be where s2[i] == '\0'. [CODE]cout << endl << "Files differ at line" << (i + 1) << endl;[/CODE] i isn't the line number, line is.

Member Avatar for WaltP
0
178
Member Avatar for JeyC

The way your compiler put things together, B is after A. You overrun A onto the start of B.

Member Avatar for dusktreader
0
79
Member Avatar for sdgz747

[QUOTE=sdgz747;1129886]I am supposed to write a program that asks for the coefficients a, b, and c of a quadratic equation ax2+bx+c=0. It needs to display to the screen one of the following: • two distinct real numbers (when b2-4ac > 0), • two distinct complex numbers (when b2-4ac < 0), …

Member Avatar for abhimanipal
0
1K
Member Avatar for latszer
Member Avatar for lllllIllIlllI

[QUOTE=Paul Thompson;1127721]I am flying from Australia to the San Francisco for a holiday in the western states for 3 weeks :) So seeing i am in Oz and i know many of you live in the US i was wondering, whats something i should see/do when over there?[/QUOTE] [URL="http://en.wikipedia.org/wiki/Yosemite_National_Park"]Yosemite[/URL]?

Member Avatar for vmanes
0
154
Member Avatar for suzi_ausi

[QUOTE=suzi_ausi;1128487]Please explain me in detail : [CODE]const char *str1 = "pointer to constant"; char *const str2 = "constant pointer"; const char *const str3 = "constant pointer to constant"; str1[0] = 'P'; // illegal! str1 = "ptr to const"; // ok str2 = "const ptr"; // illegal! str2[0] = 'P'; // …

Member Avatar for Dave Sinkula
0
289
Member Avatar for DJPlayer

[url]http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.1[/url]

Member Avatar for Dave Sinkula
0
226
Member Avatar for mrnutty

[QUOTE=Narue;1110238]I prefer "find and fix the bug" problems because they exhibit both problem solving and enough programming ability to debug.[/QUOTE] Have you got any samples you'd be willing to post?

Member Avatar for vaultdweller123
0
1K
Member Avatar for suncica2222

_CreateProcess is a typedef (an alias) for a pointer to a function with the above described signature.

Member Avatar for suncica2222
0
133
Member Avatar for cwarn23

[QUOTE=cwarn23;1125460]Hi - it's me again. I have the following code but don't exactly know what it means or how to make the opposite code. The code I currently have is [CODE]#define rotateleft(x,n) ((x<<n) | (x>>(32-n))) #define rotateright(x,n) ((x>>n) | (x<<(32-n))) [/CODE] Then can be used like the following [CODE]a = …

Member Avatar for dusktreader
0
382
Member Avatar for Dhanika

[QUOTE=Dhanika;1125726]But I managed to find out ( after some discussion with my TAs) on [COLOR="Red"]teh best solution[/COLOR]. Its simple and quite straightforward too. This code, [COLOR="Red"]uses no loops[/COLOR] or arrays or anything. have a look. :D[/QUOTE][/me builds code and runs it...] [QUOTE]123 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000101 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000110 ... …

Member Avatar for Dhanika
0
2K
Member Avatar for hsp700

Nothing simple and standard. You can go 3rd party library and mess with the screen, but the options will likely be OS dependent.

Member Avatar for Dave Sinkula
0
82
Member Avatar for mani_singh

[url=http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.2][39.2] How do I convert a std::string to a number?[/url]

Member Avatar for Dave Sinkula
0
85
Member Avatar for sfreema4

[QUOTE=nezachem;1124826]Are you guys on autopilot again? Beg to explain how null termination is related to the OP problem.[/QUOTE] I would guess that it had very much to do with the OP's description of the issue: [QUOTE=sfreema4;1124327]When I execute this I get the following output > ./bcat2 10 < input1.txt Up …

Member Avatar for tmoorez06
0
209
Member Avatar for jimFan

[QUOTE=jimFan]This programme runs fine when I compile and click the executable. But things go wrong if I do it in command-line and redirect the input stream [COLOR=Red]to[/COLOR] a text file: $a.out < inputFile[/QUOTE]Don't you mean input [I]from[/I]? What are the contents of your input file? Or do you mean to …

Member Avatar for Fbody
0
1K
Member Avatar for chankya
Member Avatar for GrimJack
0
245

The End.