2,384 Posted Topics
![]() | Re: 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] |
Re: [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 … | |
Re: [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 … | |
Re: [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. | |
Re: [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; … | |
Re: [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: | |
Re: [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] … | |
Re: 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] | |
Re: [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] | |
Re: [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] | |
Re: My preference for user input: [url]http://www.daniweb.com/tutorials/tutorial45806.html[/url] | |
Re: 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? | |
Re: [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. … | |
Re: ~0 is "all bits set", not 1. !0 is 1. | |
Re: Try to create a minimal snippet that is compilable and demonstrates the issue. | |
Re: 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 = … | |
Re: [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 … | |
Re: [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 … | |
Re: 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 … | |
Re: [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. … | |
Re: Is the file opened in text or binary mode? | |
Re: Consider the range of char. Also, abs is a reserved identifier. | |
Re: 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 … | |
Re: [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 … | |
Re: 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); … | |
Re: [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 … | |
Re: [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! ;) | |
Re: 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 … | |
Re: [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, … | |
Re: Nothing stops the recursion except when your system starts getting trashed. | |
Re: [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". | |
Re: Put your statements of lines 6 and 7 into a function. | |
Re: 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. | |
Re: 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. | |
Re: The way your compiler put things together, B is after A. You overrun A onto the start of B. | |
Re: [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), … | |
Re: Use strcmp to compare strings. Dont use gets. | |
Re: [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]? | |
Re: [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'; // … | |
Re: [url]http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.1[/url] | |
Re: [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? | |
Re: _CreateProcess is a typedef (an alias) for a pointer to a function with the above described signature. | |
Re: [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 = … | |
Re: [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 ... … | |
Re: Nothing simple and standard. You can go 3rd party library and mess with the screen, but the options will likely be OS dependent. | |
Re: [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] | |
Re: [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 … | |
Re: [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 … | |
|
The End.