2,384 Posted Topics

Member Avatar for ravinamita

[QUOTE=ravinamita;1068283]I am new to XML and have a very sketchy knowledge of C. I am writing a C program in which I need to read strings (each on a separate line) in a text file, match that string with a value enclosed in a specific tag inside an XML file, …

Member Avatar for JenniLei
0
2K
Member Avatar for Snapster5

[QUOTE=Snapster5;1069302]is the max array size for this question 5?[/QUOTE]In this example, yes. But that makes no difference for the functions you are supposed to write.

Member Avatar for Dave Sinkula
0
122
Member Avatar for PDB1982

>any ideas? Maybe [ICODE]break;[/ICODE] the input loop on the sentinel value?

Member Avatar for Dave Sinkula
0
96
Member Avatar for rico.tee

[QUOTE=jephthah;1068614]any loop can that can be done with a for statement, can also be done with a while statement. and vice versa. the details are different but the result will be the same.[/QUOTE]That reminds me of [URL="http://www.daniweb.com/forums/post94143.html#post94143"]an old post[/URL]. But I seem to have left out recursion. :P (And it …

Member Avatar for Dave Sinkula
0
116
Member Avatar for 0xCoTiNe

One way: [CODE]#include <stdio.h> int main() { const char filename[] = "file.txt"; FILE *file = fopen(filename, "r"); if ( file ) { char crossword[10][10]; int i, j; for ( i = 0; i < sizeof crossword / sizeof *crossword; ++i ) { for ( j = 0; j < sizeof …

Member Avatar for Dave Sinkula
0
115
Member Avatar for sexyzebra19

Very minor, but... [CODE] cout << " p[COLOR="Red"]\([/COLOR]" << x << ") = " << p << endl; [COLOR="Red"]/* warning: unknown escape sequence '\(' */[/COLOR][/CODE] So how about: [code] cout << " p(" << x << ") = " << p << endl; cout << " p'(" << x << …

Member Avatar for mrnutty
0
96
Member Avatar for bhas_purk
Member Avatar for hit25

You've got nested loop issues. After you get the line, the line is got. Reading "the rest of the line" will be problematic. You should check for success when you attempt to read from the file. Avoid using eof() as a loop control.

Member Avatar for hit25
0
243
Member Avatar for Bladtman242

How about something along this line? [code]nclude <iostream> #include <fstream> using namespace std; int main() { ifstream iptilvar("ip.txt"); //open filestram string line, ip; while ( getline(iptilvar, line) ) { ip = line; } string::size_type loc = ip.find_last_of(' '); if ( loc != string::npos ) { cout << ip.substr(loc + 1) …

Member Avatar for Bladtman242
0
629
Member Avatar for Mattpd

I really don't care to make up the #defines and the rest. Do you suppose you could just post a small, but complete and compilable snippet? kthxbye [edit]But the nested loops don't look like a happy thing to do.

Member Avatar for Mattpd
0
396
Member Avatar for Duncans Ghola

Are necessary headers #included prior to the lines in question? The functions calls shouldn't have the [] part. Do your headings have the curly-brace part? Your code may be long, but you've edited out important details. It's generally best not to paraphrase code.

Member Avatar for Duncans Ghola
0
214
Member Avatar for abd2

[code][color=#000000][color=red][b]#[/b][/color]include <stdio.h> [color=red]int[/color] main() { int i=2;[/color] [color=#000000] switch ( i ) { case 1[b][color=red]:[/color][/b] printf("i am in case 1\n"); break; case 2[b][color=#ff0000]:[/color][/b] printf("i am in case 2\n"); break; case 3[b][color=#ff0000]:[/color][/b] printf("i am in case 3\n"); break; default[b][color=#ff0000]:[/color][/b] printf("i am in default\n");[/color] [color=#000000] }[/color] [color=#000000] [color=red]return 0;[/color] }[/color][/code]

Member Avatar for mrnutty
1
156
Member Avatar for tomtetlaw

[QUOTE]baseentity.cpp In file included from baseentity.cpp:3: baseentity.h:8: warning: `class BaseEntity' has virtual functions but non-virtual destructor main.cpp In file included from main.cpp:3: baseentity.h:8: warning: `class BaseEntity' has virtual functions but non-virtual destructor main.cpp: In function `void split_string(const std::string&, std::vector<std::string, std::allocator<std::string> >&, char)': main.cpp:9: warning: comparison between signed and unsigned integer …

Member Avatar for tomtetlaw
0
240
Member Avatar for Vitriolics

getc returns an int; EOF is an int. [edit]Also, you'll need to rewind fp the way you're doing things.. [code]int countlines(FILE* fp) { int c, lines = 0; while ( (c = getc(fp)) != EOF ) { if ( c == '\n' ) lines++; } [COLOR="Red"]rewind(fp);[/COLOR] return lines; }[/code]

Member Avatar for Dave Sinkula
0
124
Member Avatar for mrnutty

[code]int main(int O,char**I){int _[]={23,10,7,25,9,26,13,-1};if(I){O=0;}if(_[O]>-1){main(++O,0);putchar('|'-_[--O]);}return 0;}[/code](Lame effort of mine, MS barks, gcc is ok.)

Member Avatar for Ene Uran
4
113
Member Avatar for halluc1nati0n

[QUOTE=halluc1nati0n;1059989]Why'd they use char str[80] in the example??? What types can be used?[/QUOTE] It sounds like you may be confused as to how an array/C-style string is passed to a function in C and C++. In the example, the array for a C-style string [ICODE][COLOR="Green"]str[/COLOR][/ICODE] is declared. [code]/* strcat example …

Member Avatar for Dave Sinkula
0
110
Member Avatar for PDB1982

[QUOTE=PDB1982;1058551]But, I don't know where the -858993460 is coming from...!?! 2). Where should I go from here?[/QUOTE] Read input, [I]then[/I] print it?

Member Avatar for jonsca
0
136
Member Avatar for PDB1982

Keep track of the index of the highest value while taking input. Initialize to the first element: [code] int hi = 0;[/code] When you find a new highest value, capture the index: [code] if ( votes[i] > votes[hi] ) { hi = i; }[/code]The winner is [ICODE]candidate[hi][/ICODE].

Member Avatar for Clinton Portis
0
134
Member Avatar for Darth Vader

The [URL="http://web.archive.org/web/20050207005628/http://dev.unicals.com/papers/c89-draft.html#4.12.2.2"]difftime[/URL] function returns the difference expressed in seconds as a double.

Member Avatar for Excizted
0
85
Member Avatar for ahamed101

Your first example may not be working the way you think it is. The #include directive is like a copy-and-paste that happens at compile time. You can't do it at runtime.

Member Avatar for gerard4143
2
1K
Member Avatar for klackey19

The compiler warns because generally it isn't what someone wants. But multiplying by two is the same as adding self to self. [edit]Heh. But that won't work with pointers. Probably also for good reason.

Member Avatar for Narue
0
141
Member Avatar for cmk2901

Try printing the bytes in the buffer rather than printing the buffer as a string (especially when you are not treating buffer as a string).

Member Avatar for Ancient Dragon
1
170
Member Avatar for agentmusic
Member Avatar for kolosick.m188

Expected input and output would be helpful. Providing a small snippet of a simple test, minimal but complete and compilable, would too. "This code doesn't do what I want (and I'm not going to tell you what that is)" isn't very helpful. I have no idea how this compares to …

Member Avatar for Dave Sinkula
1
107
Member Avatar for bufospro

[QUOTE=bufospro;1051624]I want to make a program that reads a string. But I would like to read only characters, neither numbers nor special characters(@,#$%^&*()!). Also, no spaces between characters.[/QUOTE]Use system-specific APIs and write a fair amount of character-handling code. Or use simple standard library functions and reject unwanted input. Which is …

Member Avatar for bufospro
1
107
Member Avatar for unsure

You seem to be using a lousy code editor and have "fancy quotes" instead of the plain variety. After that you'll get more syntax errors to clean up, like this [code]int calc_bonus(int sales){[/code] You need to learn how to declare, define, and call functions. So maybe take another look at …

Member Avatar for Nick Evan
0
141
Member Avatar for june_me
Member Avatar for Nick Evan
0
98
Member Avatar for Deadmon

[QUOTE=Ancient Dragon;1047685]sizeof( any pointer ) is always the same[/QUOTE]That happens to be true for the garden variety PC of today, but it is not true as a generic statement.

Member Avatar for Ancient Dragon
0
165
Member Avatar for siggivara
Member Avatar for siggivara
0
187
Member Avatar for yatman

[CODE]#include <iostream> #include <fstream> #include <cstdlib> int main() { std::ifstream file("reg.txt"); char text[80]; while ( file.getline(text, sizeof text) ) { unsigned long value = strtoul(text, NULL, 2); std::cout << "text[] = \"" << text << "\", value = " << value << "\n"; } return 0; } /* my output …

Member Avatar for donaldw
0
384
Member Avatar for candoc
Member Avatar for fopah

[code]#include <iostream> #include <string> int main() { std::string input; std::cout << "Enter a string: "; if ( getline(std::cin, input) ) { std::cout << "You entered " << input << std::endl; } return 0; }[/code]

Member Avatar for arshaad
0
168
Member Avatar for fragtech
Member Avatar for Will Gresham

I believe your expectation used to be the default behavior. The new default was an "upgrade" a while back. The compromise you see is the result of some complainin'. (If I remember things correctly.)

Member Avatar for Dani
1
111
Member Avatar for angelsherin

[QUOTE=hacker9801;643172]What's the ^ for anyway?[/QUOTE] A [URL="http://en.wikipedia.org/wiki/C%2B%2B/CLI"]C++/CLI[/URL] [URL="http://msdn.microsoft.com/en-us/library/yk97tc08.aspx"]Handle to Object on Managed Heap[/URL] I believe.

Member Avatar for amit.mcanitw
0
184
Member Avatar for abie

[QUOTE=Ancient Dragon;1043921]Yup. floats are always converted to doubles when used as function parameters.[/QUOTE][url]http://groups.google.com/group/comp.lang.c/browse_thread/thread/2aaf5360b08c89a9/1000b1f7fb33ea53?ie=UTF-8&q=float+promoted+double+function+group%3Acomp.lang.c&pli=1[/url] [QUOTE]No, that's only true if (1) you call the function without a prototype in scope, or (2) it's a variable argument to a variadic function like 'printf'.[/QUOTE]

Member Avatar for mrnutty
0
173
Member Avatar for svgreatest

[CODE]for (int i=1;i<=8;i++)[/CODE]Don't you mean this?[CODE]for (int i=0;i<8;i++)[/CODE]

Member Avatar for Dave Sinkula
0
97
Member Avatar for A Tripolation

You'll need to make a lot of changes to your functions given this sort of pattern... From (extraneous type needs to be removed, multiplication is done using [ICODE]*[/ICODE], feed the [ICODE]pow[/ICODE] function the correct number of parameters):[CODE]double height_moon (float speed, double radians, double distance_moon(float speed, double radians)) { double height_moon, …

Member Avatar for banders7
0
242
Member Avatar for shmeeps
Member Avatar for splurchner

Are you planning to point to memory you can write to before you write to it? [code] [COLOR="Red"]char *str[/COLOR], *tmp; char linein[81]; linenum = arrpos = 0; while(fgets(linein, 80, inf) != NULL) { printf("2\n");fflush(stdout);/* POINT 2 */ linenum++; sprintf([COLOR="Red"]str[/COLOR], "%c", linein[0]); [/code]

Member Avatar for Dave Sinkula
0
188
Member Avatar for crazybitez

[QUOTE=crazybitez]Does anyone know how i could get a list of all files in a given directory given the directory's path using c++?[/QUOTE][url="http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1046380353&id=1044780608"]http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1046380353&id=1044780608[/url]

Member Avatar for Ashishinani1756
0
244
Member Avatar for railmaster7

I don't think you even want the array, but instead are after this? [CODE] inFile.open(file);[/CODE]

Member Avatar for Dave Sinkula
0
206
Member Avatar for vinochick

[CODE]#include <iostream> #include <cmath> using namespace std; int main() { cout << "RAND_MAX = " << RAND_MAX << "\n"; return 0; } [/CODE]

Member Avatar for Dave Sinkula
0
905
Member Avatar for scott6480
Member Avatar for BestJewSinceJC

[QUOTE=cscgal;1042090]Therefore, my policy is to ensure 100% backwards compatibility[/QUOTE] :icon_lol:

Member Avatar for cwarn23
0
392
Member Avatar for StaticX

Do you know why you're trying to use an array of pointers to char instead of an array of char? [CODE]main(){ const int max_chars =100; int length= 0; [COLOR="Red"]char* letters[max_chars + 1];[/COLOR] String* string; string = new String(); cout << "Enter string: " ; cin.getline([COLOR="Red"]*letters[/COLOR], max_chars + 1, '\n'); string->stringLength([COLOR="Red"]*letters[/COLOR]); …

Member Avatar for StaticX
0
98
Member Avatar for raigs

Have the code mirror what you're doing: [CODE]char *VAR1([COLOR="Red"]const [/COLOR]char *VAR2)[/CODE] Also, make sure you have enough space to write into. [edit]If he wants the warning... [QUOTE=gerard4143;1041035]Try this[/QUOTE] why would a solution be to silence the warning with the cast?

Member Avatar for Dave Sinkula
0
394
Member Avatar for sonygamer

Lose the semicolon: [CODE]#define CAPACITY 128[COLOR="Red"];[/COLOR][/CODE] [edit]Avoid expressions like this: [CODE][COLOR="Red"]i=(i++)[/COLOR]%CAPACITY[/CODE] [url]http://c-faq.com/expr/ieqiplusplus.html[/url]

Member Avatar for sonygamer
0
179
Member Avatar for guccitan88

Another way of reading "7 times per line" is "output a newline every 7 times". You could do this with a separate counter (in the same loop though!) that counts to 7, outputs a newline and then is reset. Or you might use the % operator with the current loop …

Member Avatar for guccitan88
1
2K
Member Avatar for StaticX

Another way would be to write this as a function. If any character does not match, you can break the loop early and return a value indicating the "strings" do not match. If all characters do compare the same, then return a value indicating the "strings" do match. [code]#include <iostream> …

Member Avatar for Dave Sinkula
0
111

The End.