2,384 Posted Topics
Re: [QUOTE=numitori;1125027]i tink this is one solution to your problem: it takes the input code and sends it to another string without any spaces [code] #include <stdio.h> #include <string.h> int main() { char initial[256]; char * final = (char *) malloc(sizeof(final)); char temp; int i; printf("Enter string \n"); gets(initial); printf("\n"); strcpy(final, … | |
Re: The "block" function ought to handle any object: [url]http://www.daniweb.com/code/snippet216409.html[/url] | |
Re: Well, to [B]scan[/B] a [B]f[/B]ormatted [B]s[/B]tring with [B]sscanf[/B], you'd want to know the [B]f[/B]ormat of the [B]s[/B]tring to [B]scan[/B]. Perhaps you can provide an example of the incoming string? | |
Re: [QUOTE=sexyzebra19;1119661]Could someone please have a look at my code and tell me anything that can be improved? Anything at all - layout, using headers etc?[/QUOTE] Fix the errors? [QUOTE]main.cpp main.cpp: In function `int main()': main.cpp:65: error: `g6' was not declared in this scope main.cpp:65: error: `g7' was not declared in … | |
Re: Do you want the struct elements to be pointers? Or do you really mean for them to be back-to-back long integers packaged in a struct? [CODE]/** * 0x000F0000 +--------------+ ============# * 0x000F0001 | | # * 0x000F0002 | value1 | # * 0x000F0003 +--------------+ struct T # * 0x000F0004 +--------------+ … | |
Re: [QUOTE=b.bob;1121295]I have the following: [CODE] [COLOR="Red"]char* fOutMsg;[/COLOR] strcpy(fOutMsg, "03DS2"); [/CODE] -------------------------------------------------------------- in another place: [CODE] char fPpn[32] = {0}; strcpy(fPpn, " "); [/CODE] ------------------------------------------------------------------- in another location: [CODE] [COLOR="Red"]char fStr;[/COLOR] struct* ioEx; strcpy(fStr, W2A(ioEx->authcode)); [/CODE] --------------------------------------------------------------------- more: [CODE] [COLOR="Red"]char* iProdType;[/COLOR] strcpy((char*) fDef.prodtype, iProdType); [/CODE] ------------------------------------------------------------------------ and: [CODE] strcpy(fI8_GPID, "%"); [/CODE][/QUOTE] … | |
Re: Well, t is NULL -- what do you expect? [CODE] node *[COLOR="Red"]t = NULL[/COLOR]; cout<<"dati radacina arborelui "; creare(t); parcurgere([COLOR="Red"]t[/COLOR]); [/CODE] | |
Re: I think it is better to take the serialized approach you presented. Even with a POD structure the binary read/write is inherently non-portable. Nit - consider this: [code]s.read( r.type, sizeof [COLOR="Blue"]r.type[/COLOR] ); //s.read( r.type, 2 * sizeof(char) ); // ... s.read( (char*)&(r.size), sizeof [COLOR="Blue"]r.size[/COLOR] ); //s.read( (char*)&(r.size), sizeof(unsigned int) );[/code]And … | |
Re: "[URL="http://groups.google.com/group/gnu.gcc.help/msg/d97a0f655e96ce16"]Maximal munch[/URL]" [url]http://en.wikipedia.org/wiki/Maximal_munch[/url] | |
Re: [url]http://www.daniweb.com/forums/announcement118-2.html[/url] | |
Re: I'd never used it before, but apparently SlickEdit has a spell checker. It can be restricted to looking only at strings and comments. | |
Re: [QUOTE=xavier666;1116901]I tried the concept of using [icode]&[/icode] in the actual parameter and [icode]**[/icode] in the formal parameter but it gave errors.[/QUOTE] That's the direction you want to head. Perhaps post that attempt. BTW, is leaking memory like you are doing also a requirement? | |
Re: I might create a function that has this kind of a prototype: [CODE]int convert(const char *text, int inbase, int outbase);[/CODE] Pass the function the text "43" as is. Convert the "8" and the "10" to ints however you choose -- maybe even your own atoi! The convert function then does … | |
| |
Re: I've been a SlickEdit user since about 1998. I've enjoyed using this same editor while writing code to various embedded targets and the occasional PC utility. I do generally have to deal with vendor-specific IDEs in parallel, but they generally annoy me by having a much crappier set of editing … | |
Re: The user types text. Read text, as a string. Interpret the string how you choose. Maybe first check if it could be binary, if not, try decimal. The function strto[u]l would be handy, methinks. | |
Re: Bit fiddlers generally start counting at bit 0. (Which does have a nice symmetry with arrays being zero based too.) [edit]Are you familiar with things like [ICODE]&[/ICODE], [ICODE]|[/ICODE], [ICODE]~[/ICODE], [ICODE]>>[/ICODE], and [ICODE]<<[/ICODE]? I'd bet they'll be your basic 'tools'. I'm wondering what else was missed (by me) if the instructions … | |
I'm just curious -- [B]how long would it take someone to find the snippet I had in mind armed with the information I provided in this thread?[/B] [QUOTE=Dave Sinkula;1116539]I wrote some code to do this and put it in the snippets. If you want a look at it, good luck … | |
Re: [QUOTE=tinek;1116227]i have an assignment to make a program that forecast the date given by the number of days by the user including leap years. example: Input date: November 20, 2008 Input number of days to forecast: 100 Forecast date: March 01, 2009 pls. help thank you ;)[/QUOTE] I wrote some … | |
Re: Some of my tinkering from the other day: [CODE]#include <iostream> #include <fstream> #include <cstring> using namespace std; void myfind(const char *buffer, int size) { for ( int i = 0; i < size; ++i ) { const void *bytes = buffer + i; if ( memcmp(bytes, "FD", 2) == 0 … | |
Re: What's R? [I](Rhetorical)[/I] [CODE] if ( [COLOR="Red"]a[/COLOR]=="clear" )[/CODE] | |
Re: [QUOTE=Narue;1115817]Indeed. In fact, weaker programmers on a team will typically be given maintenance tasks, so code should be written with the lowest common denominator in mind, if possible. And yes, I do believe that [ICODE]x % 2[/ICODE] is more commonly understood than [ICODE]x & 1[/ICODE].[/QUOTE] Hmm. For me, I was … | |
Re: Are you new to calling functions in C++? [CODE] pickColor(colors, red, green, blue);[/CODE] | |
Re: Going with the strstr approach, and coupling that with sscanf, I might try something like this: [CODE]#include <stdio.h> #include <string.h> int main(void) { const char text[] = "Jan 15 05:46:07 gateway kernel: " "IN=eth0 OUT= MAC=00:80:c7:c3:c7:be" ":08:00:03:23:2a:a8:08:00 " "SRC=80.232.253.76 DST=80.234.144.54 " "LEN=48 TOS=0x00 PREC=0x00 TTL=108 " "ID=43600 DF PROTO=TCP SPT=3329 … | |
Re: [QUOTE=ishaiman;1110726]I have this assignment can anyone solve it?[/QUOTE] Substitute your post contents into [URL="http://www.daniweb.com/forums/post1093274.html#post1093274"]this reply[/URL]. | |
Re: What's with the comma? [CODE] else if ([COLOR="Red"]pop > 3, pop < 5[/COLOR]){ pop = pop + 2; } else if ([COLOR="Red"]pop >5, pop < 10[/COLOR]){ pop = pop + 3; } [/CODE] [QUOTE]main.cpp:102: warning: left-hand operand of comma has no effect main.cpp:105: warning: left-hand operand of comma has no … | |
Re: Null terminate the strings you read in (s and t). | |
Re: Why are you using delete on something that wasn't new'ed? Why would you even attempt to do something with temp after calling delete on it (if it were something you could delete)? | |
Re: I tend to use this type of construct: [CODE]#if defined MACRO && MACRO > 0[/CODE] because you really shouldn't be doing this [CODE]#if MACRO > 0[/CODE] if MACRO is not defined. And just doing [CODE]#ifdef MACRO[/CODE] or [CODE]#if defined MACRO[/CODE] would be true even if MACRO were defined as 0. | |
Re: [CODE]while(!fin.eof())[/CODE] [url=http://www.daniweb.com/techtalkforums/post155265-18.html]Avoid Loop Control Using eof()[/url] | |
Re: Pot shot: [CODE] if ( wcscmp ( L"[COLOR="Red"]\xD8\xA8[/COLOR]\n" , line_buffer + 3 ) == 0 ){[/CODE] The [iCODE]+ 3[/iCODE] is skipping the [URL="http://en.wikipedia.org/wiki/UTF-8#Byte-order_mark"]BOM[/URL]. The [iCODE]L"ب\n"[/iCODE] part gets mistranslated for me in the source code. As far as knowing shortcuts, I don't know any. I'm just curious and playing along at … | |
Re: This idea may be a little bit out there, but have you thought about building the code and running it? | |
Re: [QUOTE=Lerner;1103731]An alternate would be to change the STL string into a C style string and continue to use strtok() as you have. The c_str() member method of the STL sting class can help you do that.[/QUOTE]You might want to mention that c_str() returns a pointer to a non-modifiable string, so … | |
Re: [QUOTE=WaltP;1110272]Impossible. [I]Nothing[/I] can be called before [ICODE]main()[/ICODE][/QUOTE]Nit: that's not exactly true. [CODE]#include <iostream> #include <cstdlib> #include <ctime> class T { public: T() { std::cout << "T ctor\n"; srand(time(0)); } }; T obj; int main() { std::cout << "hello world\n"; return 0; } /* my output T ctor hello world */[/CODE] | |
Re: [QUOTE=Adami;1109742]I just need to know how do I deal with the single -1 call.... :'([/QUOTE] Wouldn't you want to do what the function says and return the lowest ever? [CODE]#include <stdio.h> #include <stdarg.h> #include <limits.h> int lowest_ever(int first, ...) { static int lowest = INT_MAX; va_list arglist; /** * Handle … | |
Re: Well, since an IP address is a 32-bit integral value (IPv4), I would probably use a 32-bit unsigned integer. | |
Re: In general, you'd call it in a loop over each "row". You'd pass the parameters: pointer to the row array, its size, and the value you're looking for. Your finder function needs fixing, though, so it goes through more than one iteration. And then there is the issue of what … | |
Re: I might suggest removing the leading underscores -- that's the implementor's namespace. | |
Re: [QUOTE=rahul8590;1108375]the output got is : [COLOR="Red"]100[/COLOR][COLOR="Green"]10[/COLOR][COLOR="Red"]10[/COLOR][COLOR="Green"]-1[/COLOR][/QUOTE] Perhaps your file contains [ICODE]d[/ICODE] [iCODE]\n[/iCODE] [iCODE]\n[/iCODE] and you also print the received EOF before breaking the loop. ;) | |
Re: You open the file. In the loop you continually print out the stream, but you never read from the file and then never reach the end of it. | |
Re: [url]http://c-faq.com/expr/evalorder2.html[/url] [url]http://c-faq.com/expr/seqpoints.html[/url] | |
Re: [CODE] char filename[256] = "myfile"; FILE * pFile = fopen (filename, "w"); if (file) { /* Do stuff. */ fclose(file); } fclose (pFile);[/CODE] | |
Re: [CODE]#include <fstream>[/CODE] And resist the urge to reply to years-old threads. | |
Re: [QUOTE=nichya88;1107287]I try to understand why it gave this result, but I cannot understand the section in bold.[/QUOTE]cout knows the type and chooses how to present the object. You expect a pointer to char to print a C-style string, and it does. The same thing goes for a pointer to char. | |
Re: Did I miss where you posted the input? Do you know to avoid loop control with eof(), or is that another "requirement"? Does your compiler not bring up issues like these? [QUOTE]main.cpp main.cpp: In member function `cStudent& cStudent::operator=(cStudent)': main.cpp:40: warning: no return statement in function returning non-void main.cpp: At global … | |
Re: Heh. No, a space is not a null. The space delimited input you are using is delimited by spaces. Use getline if you want to get a line. | |
Re: [QUOTE=johndoe444;1106367]Why do people invent something that is that crazy?[/QUOTE] When you need it, you need it. And then it's there for you. | |
Re: My usual advice is to read all user input as a string; if you want a numeric input, convert the string. Otherwise there is some cleanup of cin that you can do. There must be countless examples of this that can by found by searching this forum. | |
Re: Read and discard lines 1 and 2, then read line 3 and you've got it. |
The End.