2,384 Posted Topics

Member Avatar for Kombat

[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, …

Member Avatar for Kombat
0
152
Member Avatar for ssquared

The "block" function ought to handle any object: [url]http://www.daniweb.com/code/snippet216409.html[/url]

Member Avatar for ssquared
0
228
Member Avatar for liljj2005

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?

Member Avatar for Dave Sinkula
0
211
Member Avatar for sexyzebra19

[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 …

Member Avatar for jonsca
0
135
Member Avatar for ibuguser

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 +--------------+ …

Member Avatar for gerard4143
0
147
Member Avatar for b.bob

[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] …

Member Avatar for dusktreader
0
380
Member Avatar for 28daniela28

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]

Member Avatar for 28daniela28
0
139
Member Avatar for WolfPack

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 …

Member Avatar for Ancient Dragon
0
2K
Member Avatar for abhimanipal

"[URL="http://groups.google.com/group/gnu.gcc.help/msg/d97a0f655e96ce16"]Maximal munch[/URL]" [url]http://en.wikipedia.org/wiki/Maximal_munch[/url]

Member Avatar for SpyrosMet
0
265
Member Avatar for xtian002
Member Avatar for abhimanipal
0
208
Member Avatar for ithelp

I'd never used it before, but apparently SlickEdit has a spell checker. It can be restricted to looking only at strings and comments.

Member Avatar for Dave Sinkula
0
95
Member Avatar for xavier666

[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?

Member Avatar for xavier666
0
144
Member Avatar for jmstickney

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 …

Member Avatar for Dave Sinkula
0
86
Member Avatar for cktbrd
Member Avatar for Stefano Mtangoo

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 …

Member Avatar for VilePlecenta
0
232
Member Avatar for Kombat

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.

Member Avatar for Salem
0
117
Member Avatar for Kombat

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 …

Member Avatar for abhimanipal
0
268
Member Avatar for Dave Sinkula

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 …

Member Avatar for VernonDozier
0
247
Member Avatar for tinek

[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 …

Member Avatar for Dave Sinkula
0
100
Member Avatar for Mallos31

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 …

Member Avatar for Mallos31
0
195
Member Avatar for Anarionist
Member Avatar for Anarionist
0
266
Member Avatar for NickRx

[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 …

Member Avatar for Narue
0
159
Member Avatar for sblass92
Member Avatar for sblass92
0
769
Member Avatar for techno_weenie

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 …

Member Avatar for techno_weenie
0
152
Member Avatar for ishaiman

[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].

Member Avatar for sidra 100
-3
301
Member Avatar for bman214

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 …

Member Avatar for bman214
0
143
Member Avatar for nathanurag
Member Avatar for c0d3x
Member Avatar for Yellowdog428

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)?

Member Avatar for Yellowdog428
0
162
Member Avatar for Iam3R

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.

Member Avatar for Dave Sinkula
0
103
Member Avatar for Dimitar

[CODE]while(!fin.eof())[/CODE] [url=http://www.daniweb.com/techtalkforums/post155265-18.html]Avoid Loop Control Using eof()[/url]

Member Avatar for Dimitar
0
160
Member Avatar for freeseif

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 …

Member Avatar for Ancient Dragon
2
2K
Member Avatar for tien113

This idea may be a little bit out there, but have you thought about building the code and running it?

Member Avatar for Salem
-1
551
Member Avatar for FatimaRizwan

[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 …

Member Avatar for jonsca
0
447
Member Avatar for rkulp

[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]

Member Avatar for hag++
0
245
Member Avatar for Adami

[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 …

Member Avatar for Adami
0
121
Member Avatar for Excizted

Well, since an IP address is a 32-bit integral value (IPv4), I would probably use a 32-bit unsigned integer.

Member Avatar for Excizted
0
207
Member Avatar for gamerchick

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 …

Member Avatar for abdelhakeem
0
129
Member Avatar for Ancient Dragon

I might suggest removing the leading underscores -- that's the implementor's namespace.

Member Avatar for Ancient Dragon
2
318
Member Avatar for rahul8590

[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. ;)

Member Avatar for nezachem
0
200
Member Avatar for said.amsur

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.

Member Avatar for said.amsur
0
230
Member Avatar for AAAKsu

[url]http://c-faq.com/expr/evalorder2.html[/url] [url]http://c-faq.com/expr/seqpoints.html[/url]

Member Avatar for Salem
0
67
Member Avatar for John_W

[CODE] char filename[256] = "myfile"; FILE * pFile = fopen (filename, "w"); if (file) { /* Do stuff. */ fclose(file); } fclose (pFile);[/CODE]

Member Avatar for Dave Sinkula
0
130
Member Avatar for johnson9000

[CODE]#include <fstream>[/CODE] And resist the urge to reply to years-old threads.

Member Avatar for Dave Sinkula
0
160
Member Avatar for nichya88

[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.

Member Avatar for nichya88
0
139
Member Avatar for atticusr5

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 …

Member Avatar for Anarionist
0
132
Member Avatar for flyingguitar

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.

Member Avatar for flyingguitar
1
96
Member Avatar for johndoe444

[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.

Member Avatar for Dave Sinkula
0
319
Member Avatar for chukka32

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.

Member Avatar for chukka32
0
269
Member Avatar for BoB3R
Member Avatar for Dave Sinkula
0
128

The End.