2,384 Posted Topics
Re: [QUOTE=gerard4143;1040027]Is this the proper way to zero the first 12 bits of an address? [CODE]void *ans = (void*)((unsigned long)addr & [COLOR="Red"]((0UL - 1) ^ 0xfff)[/COLOR]);[/CODE] Where addr is any user process memory address.. Note this method works...I just want to know if there is a better way[/QUOTE] That kind of … | |
Re: Used unsigned integral types when dealing with bits. [code]#include <stdio.h> #include <stdlib.h> int main() { unsigned short m1 = 0xf000, m2 = 0x0f00, m3 = 0x00f0, m4 = 0x000f; printf("%hu %hu %hu %hu\n", m1, m2, m3, m4); printf("%hx %hx %hx %hx\n", m1, m2, m3, m4); return 0; } /* my … | |
Re: Q: Before signing the death certificate had you taken the man's pulse? A: No. Q: Did you listen for a heart beat? A: No. Q: Did you check for breathing? A: No. Q: So when you signed the death certificate you hadn't taken any steps to make sure the man … | |
Re: [QUOTE=Gem74;1037253]I saved "input_data.txt" in the header files, see below. [CODE]#include "input_data.txt.h"[/CODE][/QUOTE]Huh? If you're trying to open the file for input, you use this bit here: [CODE]ifstream inputFile;[/CODE] Open the file and read it? | |
![]() | Re: Use strcpy to copy a string. You've got more going wrong in that code, though. I think you're after something that might look a bit like this: [CODE]#include <string.h> typedef struct { int age; char name[50]; } Person; Person newperson(char *name, int age) { Person temp; strcpy(temp.name, name); temp.age = … ![]() |
Re: How about a final else? And don't use the comma here: [CODE]else if (numtick >100,000)[/CODE] | |
Re: One way it was done ages ago elseweb was [code], [quote], and [syntax]. The syntax tags were used for the "fancy" code tags. Quote in monospace to me would look stupid. [edit]Keeping the fonts, but limiting them, would also have handled the way [icode] is used. Some of the "common" … | |
Re: My usual advice is to always read all user input as a string. If you want a numeric value, attempt to perform a conversion. If the conversion fails, issue a message or something; otherwise you successfully obtained a numeric value, so continue. | |
Re: [URL="http://web.archive.org/web/20050207005628/http://dev.unicals.com/papers/c89-draft.html#4.5.6.4"]fmod[/URL] | |
Re: [CODE]team temp[1];[/CODE] This has only one element: [iCODE]temp[0][/iCODE]. [CODE][COLOR="Red"]temp[1][/COLOR] = teams1[(j-1)]; teams1[(j-1)] = teams1[j]; teams1[j] = [COLOR="Red"]temp[1][/COLOR];[/CODE] | |
Re: Two words ;) :[INDENT]Spare the rod, spoil the child.[/INDENT]IMO those who don't know what they are doing [I]REALLY[/I] screw it up. Whether that entails spankings or lack thereof, dunno. | |
Re: [CODE]while((c [COLOR="Red"]=[/COLOR] getchar())!= EOF)[/CODE] And what does your function return for non-alpha input? | |
Re: [url]http://en.wikipedia.org/wiki/Comparison_of_text_editors[/url] | |
Re: [QUOTE=neithan;1031915]Ok but, i'm sorry if this sound ignorant which probably will, isn't C89 too old? I look it up and this C99 thing works with those issues, right? Why still thinking of C89? (remember i'm a beginner)[/QUOTE]C89 is de facto standard for C, and it is also the base of … | |
Re: I get an odd warning: [CODE]switch ( opcion ) [COLOR="Red"]// warning: unreachable code at beginning of switch statement[/COLOR] { case 1:[/CODE]I think this has something to do with using the language extension VLA: [CODE]float polinomio[n];[/CODE]I don't know exactly what the issue here is -- gcc is trying to clue me … | |
Re: I had to patch some syntax errors to get to the link, so I'm not sure why you weren't seeing them. With regard to the linker errors: [url]http://parashift.com/c++-faq-lite/templates.html#faq-35.12[/url] ? | |
Re: [QUOTE=neithan;1030800]What am i missing?[/QUOTE]Hmm. [QUOTE]Input: web char x -> w int x --> 119 char x -> e int x --> 101 char x -> b int x --> 98 Input: foo char x -> f int x --> 102 char x -> o int x --> 111 char x … | |
Re: [code]int main() { FILE *filetext; FILE *filecopied; char text[50]; filetext=fopen("filetext.txt","r"); filecopied=fopen("filecopied.txt","w"); if ( (filetext==NULL) || (filecopied==NULL) ) { printf ("A file cannot be opened"); return 1; } [COLOR="Red"]while ( fgets(text, sizeof text, filetext) ) { char first[10]; if ( sscanf(text, "%9s", first) == 1 ) { fprintf(filecopied, "%s\n", first); } … | |
| |
Re: You might find such a thing here, perhaps in the snippets, maybe a previous forum thread. So a search might be helpful to you. | |
Re: For a value 0-9, you can just add [FONT=Courier New]'0'[/FONT] to get the corresponding digit character. [code]#include <stdio.h> int main(void) { char text[] = "StringX"; int digit; for (digit = 0; digit < 10; ++digit) { text[6] = [COLOR=Blue]digit + '0'[/COLOR]; puts(text); } return 0; } /* my output String0 … | |
Re: [CODE] fin.open("numlist.dat"); fout.open("numlist.dat");[/CODE] Perhaps first open for input. Then after you've extraced what you want and closed the file, then open the same file for output. | |
Re: This is array of pointers to string literals:[CODE]char *MONTH[] = {"January","February","March","April","May","June","July","August","September","October","November","December"};[/CODE]String literals are not writable. Same here: [CODE]REPLACE("The month is: January."); // Should be: "The month is: Enero"[/CODE] | |
Re: [url]http://www.parashift.com/c++-faq-lite/templates.html#faq-35.12[/url] ? | |
![]() | Re: [QUOTE=Odc;1027764]Hi guys, I've got a simple bool 2D array that is set to false by default. I'm filling it with random 'true' values. I am then trying to make it symmetrical i.e. array[i][j] = array[j][i] However, this doesnt seem to be working and I was wondering why. I've been trying … |
Re: [url]http://c-faq.com/varargs/index.html[/url] [url]http://c-faq.com/varargs/varargs1.html[/url] | |
![]() | Re: I wrote some snippets on parsing some time ago. [url]http://www.daniweb.com/code/snippet216535.html[/url] [url]http://www.daniweb.com/code/snippet216569.html[/url] [url]http://www.daniweb.com/code/snippet216682.html[/url] [url]http://www.daniweb.com/code/snippet216681.html[/url] Perhaps something there will give you an idea for a starting point. ![]() |
Re: [url]http://www.daniweb.com/tutorials/tutorial45806.html[/url] -- the "Read an Floating Point ..." links have additional possibilities better suited to your task. | |
Re: [CODE]for ( int x=0; x<3; x++ )[COLOR="Red"];[/COLOR][/CODE] Do you know what the semicolon does to your intended loop? | |
Re: Don't put data definitions in header files. Header guards will only ensure that only one copy exists in each source file in which it is included, but as you see you will get linker errors for multiple definitions. Put data and function definitions in source files. Move the data definition … | |
Re: [QUOTE=majestic0110;1001389]Maybe we could have an option to neg rep a member UPTO our maximum neg rep amount? I don't think I have ever neg repped anyone actually![/QUOTE]I had asked for this years ago, I believe: essentially the DevShed approach of choosing the amount of both positive and negative rep. I'd … | |
Re: [QUOTE=rmcummings;1025357]I am new to C++ and am writing a program that will call other functions. I keep getting an error for a undeclared identifier for "vowel" in this section of code. Can anyone help?[/quote]I get different errors with the code you posted (which would have formatting preserved if you used … | |
Re: [QUOTE=firstPerson;1023044][code]A = r+5(r-2) = 28 = r + 5r - 10 = [COLOR="Red"]28[/COLOR] //distributive rule = 6r - 10 = [COLOR="Red"]20[/COLOR] //add like trms[/code][/QUOTE]Where'd the 28 go and the 20 come from? | |
Re: You kinda need to know whether the binary contains LE or BE data. Some somewhat related FAQs: [url]http://c-faq.com/misc/endiantest.html[/url] [url]http://c-faq.com/cpp/ifendian.html[/url] [url]http://c-faq.com/misc/byteswap.html[/url] Or perhaps consider a text file. | |
Re: Change [CODE] [COLOR="Green"]do{ fgets(texto,50,archivopar);[/COLOR] if (i % 2 == 0) { fprintf(archivocopiado,"%s\n",texto); } if (archivopar!=EOF) { i=i+1; } [COLOR="Green"]}while(archivopar!=EOF);[/COLOR][/CODE]to[CODE] [COLOR="Red"]while(fgets(texto,sizeof texto,archivopar)) {[/COLOR] if (i % 2 == 0) { fprintf(archivocopiado,"%s\n",texto); } if (archivopar!=EOF) { i=i+1; } [COLOR="Red"]}[/COLOR][/CODE]...more or less. | |
Re: [QUOTE][CODE]template <typename Comparable> LeftistNode* LeftistHeap<Comparable>::merge( LeftistNode *h1, LeftistNode *h2) //<----------------------problem code[/CODE][/QUOTE] [CODE]template <typename Comparable> [COLOR="Red"]typename LeftistHeap<Comparable>::[/COLOR]LeftistNode* LeftistHeap<Comparable>::merge( LeftistNode *h1, LeftistNode *h2)[/CODE]? [url]http://groups.google.com/group/comp.lang.c++/browse_thread/thread/830178e40acca27a/2825ed52b5ae3fac?ie=UTF-8&q=group%3Acomp.lang.c%2B%2B+expected+constructor+destructor+or+type+conversion&pli=1[/url] | |
Re: [url]http://eternallyconfuzzled.com/tuts/datastructures/jsw_tut_skip.aspx[/url] ? | |
Re: [code]//Here is when you help me drawing the rectangle :)[/code]Funny. :) Assuming a solid rectangle, you have nested loops: outer loop counts rows, inner loop counts columns; inner loop contains output of char1, at the end of the inner loop you output a newline. A typical loop would be such … | |
Re: [url]http://c-faq.com/fp/fpequal.html[/url] | |
Re: Why not just add two int's and let the compiler perform the crap you don't have to? | |
Re: Would you like us to write the whole thing for you and pretty it up nice? [URL="http://www.daniweb.com/forums/announcement8-2.html"]Or can you show us where it is that you need assistance[/URL]? | |
Re: Some starters: Sort out your confusion about strings and numbers. Assignment is [ICODE]=[/ICODE], comparison is [ICODE]==[/ICODE]. Multiline blocks are not determined by indentation in this curly-brace language. | |
Re: You might want to add the compiler switch -Wall to turn up more errors and warnings. I can't build what you posted. [edit]With some rearranging and reasonable guesses for changes to your code, I was able to build it and it segfaults here in [ICODE]correctNumber[/ICODE]: [CODE] else if ( ptr->next!=NULL … | |
Re: [URL="http://www.daniweb.com/forums/announcement118-2.html"]Post the code of your attempt[/URL]. | |
Re: [QUOTE=amrith92;1019673]You could try this: [CODE] fgets(line, 1000, in); while ([COLOR="Red"]! feof(in)[/COLOR]) { // ... }[/CODE][/QUOTE][URL="http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1046476070&id=1043284351"]Why it's bad to use feof() to control a loop[/URL] [edit]I think the [ICODE]"rt+"[/ICODE] mode is a nonstandard extension meaning [ICODE]"r+"[/ICODE]. [edit]And it might be preferable to do [CODE]fgets(line, [COLOR="Green"]sizeof line[/COLOR], in);[/CODE] instead of [code]fgets(line, [COLOR="Red"]1000[/COLOR], … | |
Re: [QUOTE=Gaiety;1018153]instead of [CODE]p = malloc(length+1); [/CODE] use [CODE]p = (char *) malloc(length+1); [/CODE] [/QUOTE]In C++ the cast is necessary, [URL="http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1047673478&id=1043284351"]in C prefer not to cast[/URL]. |
The End.