2,384 Posted Topics
Re: [QUOTE=Sukhbir]Can someone explain me how these character or escape sequence are treated while finding string size(through sizeof() operator) \0 \n \a \1 \2 for example char str[]="\1abc\0\0" pls explain me in detailed[/QUOTE][code]#include <stdio.h> #include <string.h> void foo(const char *s, size_t size) { size_t i; printf("size = %d\n", (int)size); printf("strlen(s) = … | |
Re: [QUOTE=big buc's fan][code] // (30 lines) if (charge>10) // flat rate of 10 dollars is charged charge=10; return charge; } [color=Red][b] {[/b] // What is this doing here?[/color] double hours[CARS]; // store hours parked by the different cars[/code][/QUOTE]I believe your compiler is asking the same question. If the whole code … | |
Re: [QUOTE=nanosani]#include <stdio> // stdio is the newer version of stdio.h[/QUOTE]ITYM <cstdio> | |
Re: [code]#include <stdio.h> int main(void) { int x = 6, y = 2 * x * x * x + 5; [color=Red]printf("x = %d, y = %d\n", x, y); return 0; }[/color] /* my output x = 6, y = 437 */[/code]Man... open a book. | |
Re: [QUOTE=nanosani]c) y = 2 * (x ^3) + 5;[/QUOTE]Why do you exclusively OR x with 3? You may be interested in the [url="http://www.rt.com/man/pow.3.html"]pow[/url] function. | |
Re: [QUOTE=XianBin]main() function is have tow paras like this : argv[], argc int main(argv[],argc).[/QUOTE]ITYM[code]int main(int argc, char *argv[])[/code][QUOTE=XianBin]you can confirm if user input "<" character in DOS prompt.while argv[] was contain a "<" char , you can create a file and save input strings in it.[/QUOTE]Redirection will not pass the redirection … | |
Re: [QUOTE=Mahen]Hi everyone, i wanted my program to create another small program, but it stopped at "\x00", why and what can i do. Thnaks #include <stdio.h> int main() { FILE *out; out = fopen("c:\\cpy.exe", "wb"); fprintf(out, "\xCD\x21\x00\xCD\x21"); fclose(out); return 0; }[/QUOTE]Because "\x00" terminates the string. | |
Re: Increment the object pointed to by [font=Courier New]p[/font], then increment the pointer [font=Courier New]p[/font] (point to the next object).[code]#include <stdio.h> int main(void) { char text[] = "1b#", *p = text; printf("text = \"%s\", p(%p) = \"%s\", *p = '%c'\n", text, (void*)p, p, *p); ++*p++; printf("text = \"%s\", p(%p) = \"%s\", … | |
Re: How To Write Dangerous Code 101[CODE][url="http://www.eskimo.com/%7Escs/C-faq/q12.23.html"]gets[/url] (pass);[/CODE] | |
Re: One way:[code]#include <stdio.h> int main(void) { int a,b; char line [ BUFSIZ ]; for ( ;; ) { fputs("Enter two integer: ", stdout); fflush(stdout); if ( fgets(line, sizeof line, stdin) ) { if ( sscanf(line, "%d%d", &a, &b) != 2 ) { return 0; } printf("a = %d, b = … | |
Re: [code]char str[] = "\12345s\n";[/code]This is equivalent to the following.[code]char str[] = {0123,'4','5','s','\n','\0'};[/code]The array has six elements, each of one byte in size -- so [font=Courier New]sizeof[/font] reports the array size as 6. | |
Re: [url=http://www.ecst.csuchico.edu/~beej/guide/net/]Beej's Guide to Network Programming[/url] | |
Re: [code]if(c == ([color=Red]SPACE || '\n'[/color])) { if(c == SPACE) space++; if(c == '\n') newline++; } else other++; }[/code]The highligted code likely is not what you intend: it is a logical OR of [font=Courier New]' '[/font] with [font=Courier New]'\n'[/font] -- which results in true, a value of 1 (not the character … | |
![]() | Re: [code] cin.getline(words,50,'\n'); //write to it file<<words;[/code] ![]() |
Re: [QUOTE=iamboredguy]I'm trying to use sequential binary file editing in C++. I use a temporary file. I have to make the changes in the file by storing the modified data in the temp file. Then I delete the original file and rename the temp as the original. The problem is the … | |
Re: [QUOTE=Chainsaw]Postfix ++ has a higher precedence than prefix *.[/QUOTE]I think that [url="http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&selm=990j7i%24u9%241%40elf.bsdi.com&rnum=5"]this explanation[/url] is a little more detailed. | |
Re: for (int k=0; k<=7; k++) if (a[k] > a[k+1]) You're going off the end of the array. for (int k=0; k<7; k++) if (a[k] > a[k+1]) | |
Re: [QUOTE=wild_potatos]Hi guys / girls i am new in this forum and i hope you could help me in this problem. i programmed a link list which stores some information one of them is strings and i entered them using the function gets(); instead of scanf(); to enable the program to … | |
Re: [code]#include <stdio.h> #include <string.h> int main(void) { int r, c, rows, cols; const char filename[] = "file.txt"; FILE *file = fopen(filename, "r"); if ( file ) { if ( fscanf(file, "<matrix> rows = %d; ", &rows) == 1 && fscanf(file, "cols = %d; ", &cols) == 1 ) { for … | |
Re: >can u please xplain' wat this error means: Quite often you get this when you prototype a function, but never define it. | |
Re: [url]http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1045691686&id=1043284392[/url] | |
Re: >why can someone explain me You are comparing [font=Courier New]signed[/font] and [font=Courier New]unsigned[/font] values. The [font=Courier New]signed[/font] value gets promoted to an [font=Courier New]unsigned[/font] value for the comparison and ends up being very large. | |
Re: Microsoft-specific [url="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccelng/htm/pragm_6.asp"]pragmas[/url] need not work anywhere but with a Microsoft toolchain.[code]#pragma comment(lib, "ws2_32")[/code][quote="Mahen"]I use the LCC compiler and linker on windowsXP.[/quote]What does the LCC documentation say about linking to specific libraries? | |
Re: [url]http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1046134349&id=1043284351[/url] | |
Re: [code]#include<iostream.h> // [url="http://www.cpp-home.com/forum/viewtopic.php?t=252"]deprecated header[/url] void main() // [url="http://www.eskimo.com/%7Escs/C-faq/q11.12.html"]wrong[/url], [url="http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1044841143&id=1043284376"]wrong[/url], [url="http://www.research.att.com/%7Ebs/bs_faq2.html#void-main"]wrong[/url], [url="http://www.cpp-home.com/forum/viewtopic.php?t=266"]wrong[/url], [url="http://www.eskimo.com/%7Escs/readings/voidmain.960823.html"]wrong[/url], [url="http://users.aber.ac.uk/auj/voidmain.shtml"]wrong[/url] { cout<<"hello"; // [url="http://www.eskimo.com/%7Escs/C-faq/q12.4.html"]a similar issue in C[/url] }[/code][QUOTE=Sukhbir]//IF WE COMPILE THIS PROGRAMME IT WILL NOT PRINT HELLO ON U'R SCREEN.TELL ME WHY & TELL ME PROCEDURE HOW IT PRINT USING COUT IN VC++[/QUOTE]You do not end … | |
Re: I'd say it depends on what you intend on what you want to do with a language. It helps, however. | |
Re: [QUOTE=Frogstar]So it's only counting the first number from DB.txt, ie not updating the 'correct' string in the comparison if statement, and i don't understand why not, seeing as it's updating it in the cout statement. Any ideas?[/QUOTE]It looks to me like you are finding a value [font=Courier New][i]correct[/i][/font] from [font=Courier … | |
Re: [QUOTE=freesoft_2000]fflush(stdin); // This is to flush the input[/QUOTE]Wrong! [url="http://www.eskimo.com/~scs/C-faq/q12.26.html"]http://www.eskimo.com/~scs/C-faq/q12.26.html[/url] | |
Re: Could you show more of the code? Specifically the actual declarations for the variables would be helpful. I find no such issue with this minimal code sample. [code]#include <stdio.h> int main(void) { float ovrh = 1.0F, wr = 1.0F, z = 1.0F, Fees = ovrh + (wr * z); printf("Fees … | |
Re: Use a loop.[code][color=Red]#include <iostream> using std::cout; using std::cin; using std::endl;[/color] [color=Red]int [/color]main() { [color=Blue]for ( ;/* your condition here*/; )[/color] [color=Blue]{[/color] float x,y; cout << "Please enter one number "; cin >> x; y = x * x; cout << "The square of the number you enter is " << … | |
![]() | Re: >and when i enter a password... i want it to reveal the code in this form "*****". How should i do that? A [url="http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1045691686&id=1043284392"]C example[/url] (second snippet).[url="http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1045691686&id=1043284392"] [/url] |
Re: [url="http://www.codeproject.com/buglist/linkererrors.asp?df=100&forumid=15354&exp=0&select=548037"]Here[/url] and [url="http://www.experts-exchange.com/Programming/Programming_Languages/MFC/Q_21035721.html"]here[/url] it mentions something like this:[quote]Check your project settings under 'C++|Code generation'. That should read "Multithreaded DLL"[/quote][url="http://www.google.com/search?q=error+LNK2005+debug+release"]Other possibilities[/url]. | |
Re: Perhaps you missed the [url="http://www.daniweb.com/techtalkforums/announcement.php?f=8&announcementid=2"]announcement[/url] at the top of the page. | |
Re: It could look so much nicer if you wrapped your code with CODE tags. if ( i = 1 ) { if ( j = 1 ) { if ( k = 1 ) Assignment is `=`, comparison is `==`. And array indices are zero based. | |
Re: Integers are not floating point. Using [font=Courier New]sscanf[/font] to convert the command line text is my recommendation; with error checking, and using the [font=Courier New]+[/font] symbol itself, it might be as follows. [code]#include <stdio.h> #include <stdlib.h> int main(int argc, char **argv) { double a, b; if ( argc > 3 … | |
Re: First, [url="http://www.eskimo.com/%7Escs/C-faq/q12.20.html"]avoid scanf[/url]. Second, use a floating point type to enter a floating point value.[code]#include <stdio.h> int main() { [color=Red]double[/color] number; fputs("Enter number: ", stdout); fflush(stdout); if ( scanf("[color=Red]%lf[/color]", &number) == 1) { printf("number = %g\n", number); } return 0; } /* my output Enter number: 23.45 number = 23.45 … | |
Re: I believe you want to use a [url="http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-38.12"]forward declaration[/url]. | |
![]() | Re: Something like this? #include <iostream> void disp(int a[][[color=Red]2[/color]]) { for ( int i = [color=Red]0[/color]; i [color=Red]< [color=black]3[/color][/color] ; i++ ) [color=Red]{[/color] for ( int j = [color=Red]0[/color]; j [color=Red]< [color=black]2[/color][/color] ; j++ ) { std::cout << a[i][j] [color=Red]<< ' ';[/color] } [color=Red]std::cout << std::endl;[/color] [color=Red]}[/color] } int main() { … |
Re: [url="http://www.eskimo.com/%7Escs/C-faq/q3.3.html"]http://www.eskimo.com/~scs/C-faq/q3.3.html[/url] [url="http://www.eskimo.com/%7Escs/C-faq/q3.8.html"]http://www.eskimo.com/~scs/C-faq/q3.8.html[/url] [url="http://www.eskimo.com/%7Escs/C-faq/q3.1.html"]http://www.eskimo.com/~scs/C-faq/q3.1.html[/url] [url="http://www.eskimo.com/%7Escs/C-faq/q3.9.html"]http://www.eskimo.com/~scs/C-faq/q3.9.html[/url] [url="http://www.eskimo.com/%7Escs/C-faq/q3.2.html"]http://www.eskimo.com/~scs/C-faq/q3.2.html[/url] | |
Re: [QUOTE=chound]#include<iostream.h> //header file for basic input and output functions void main() //main function { cout<<"Hello world"<<endl; //prints out "Hello world" and endl clears the stream }[/QUOTE][list=1] [*]Please use code tags when posting code ([code][/code]). [*][font=Courier New]#include<iostream.h>[/font] is decprecated. [*][font=Courier New]void main()[/font] is incorrect for a hosted implementation. [/list] | |
Re: This is because when you have several modules, you don't want the code to be in more than one place. The [font=Courier New]#include[/font] directive essentially copies the contents of the file into your source module. If you have 5 modules that each include a header that contains actual code, you … | |
Re: Let's say you want an interactive program to input two numbers, add them together, and display the result. The user types some text, right? Was that text actually representing a valid number? Or do you just blindly add two values that may or may not be there. Data validation, in … | |
Re: >it's fine when i run only one of the sorts, but if i run both, moves comes out to 0. If you've sorted the list, just how many swaps do you think you'd need to sort the list? | |
Re: I believe it is invalid syntax. Did you mean a declaration for an array of pointers returning [font=Courier New]int[/font] and taking no parameters? [code]#include <iostream> int foo() { std::cout << "foo\n"; return 0; } int bar() { std::cout << "bar\n"; return 0; } int main() { int [color=Red]([/color]*p[][color=Red])[/color]() = {foo,bar}; … | |
Re: [QUOTE=matt768]I don't know much about c programming at all, as I have only been doing it for about five hours, any help would be much appreciated[/QUOTE]Post your attempt with any error messages and the specific questions you have. Or read [url="http://www.daniweb.com/techtalkforums/announcement.php?f=8&announcementid=2"]this[/url]. | |
Re: This isn't [font=Courier New]#include[/font]d by a C file, is it? | |
Re: Anyone who [i]recommends[/i] [font=Courier New][url="http://www.eskimo.com/~scs/C-faq/q12.26.html"]fflush(stdin)[/url][/font] is awarded instant newbie status. [url="http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1052863818&id=1043284351"]It is not correct[/url], and [url="http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1044873249&id=1043284392"]there are other ways to accompish its intended effect[/url]. | |
Re: #1 [url="http://search.microsoft.com/search/results.aspx?view=msdn&st=b&na=82&qu=C2143&s=1&swc=4"]C2143[/url] #2 [url="http://search.microsoft.com/search/results.aspx?view=msdn&st=b&na=82&qu=C2501&s=1&swc=4"]C2501[/url] #3 [url="http://search.microsoft.com/search/results.aspx?view=msdn&st=b&na=82&qu=C3265&s=1&swc=4"]C3265[/url] #4 [url="http://search.microsoft.com/search/results.aspx?view=msdn&st=b&na=82&qu=C1010&s=1&swc=4"]C1010[/url] | |
Re: [size=2][url="http://pw2.netcom.com/%7Etjensen/ptr/pointers.htm"][b]A TUTORIAL ON POINTERS AND ARRAYS IN C[/b][/url] [url="http://pw2.netcom.com/%7Etjensen/ptr/ch8x.htm"]CHAPTER 8: Pointers to Arrays[/url][/size] | |
Re: [code]char a[]={'a','b','c',d'}; int b[]={1,2,3,4,5}; printf("%d %d",&a[3]-a,&b[3]-b};[/code] You are taking the difference between pointers; the result is the number of objects between the two addresses. There are three objects between element 0 and element 3, regardless of the size of the objects. |
The End.