257 Posted Topics
Re: The following can be done in Linear time: (By using a method of hashing) [CODE]for each value in array { if (!visited(element)) { /* store element in new array */ visited[element] = visited /* ie mark as visited */ } }[/CODE] However, it is not space-wise efficient. And, if the … | |
Re: [url]http://www.opengroup.org/onlinepubs/009695399/functions/sleep.html[/url] Check this out. Is that what you wanted? | |
Hello, im very new to Web development. i recently intalled the Apache server on my machine running Linux(Ubuntu 9.10). i downloaded the Apache server. But, in order to run the html documents via the server, we need to place it in the /var directory right? But im denied that permission. … | |
Re: You may be interested in this: [url]http://sourceforge.net/[/url] | |
Hello, i have 2 small doubts regarding pointers. 1)im trying to defererence 4 bytes as shown, and im initializiing each byte using a char pointer. But im getting runtime errors. Code [CODE] char a = 65; char *ptr = (char *)malloc(4); int *ptr1; ptr = &a; ptr1 = &a; *ptr … | |
Hello, Well, this is not a question directly related to programming, so kindly excuse me for that. i have a small doubt regarding endianess and dereferencing of elements This is what i tried: [CODE]#include <stdio.h> int main(void) { int s = 0xFFFFFAFF - 1; int *p = &s; unsigned char … | |
Re: [url]http://forum.codecall.net/linux-tutorials-guides-tips/17681-linux-makefile-tutorial.html[/url] i hope that helps. | |
Re: @OP How about this: [CODE]cin >> num; cin >> occuranceValue; for (int index = 0, count = 0; count < occuranceValue; index++) { if (arr[index] == num) count++; } return index; // shows the index in the array where the nth occurance of num is present. [/CODE] | |
Re: @WaltP This is what the OP said: [QUOTE]I am not allowed to use arrays and I am not sure which loop to use. Here is what I have so far:[/QUOTE] @OP You could try this: [CODE]int min = 1000, max = 0, inputNumber; do { cin >> inputNumber; if (inputNumber … | |
Hello, i have a small doubt regarding the FILE structure. i looked it up in the header file (i have VC++ 2008). In this implementation, it was declared as: [CODE]struct _iobuf { char *_ptr; int _cnt; char *_base; int _flag; int _file; int _charbuf; int _bufsiz; char *_tmpfname; }; typedef … | |
Hello. i had seen in some places, the following piece of code: [CODE](void *)2[/CODE] Can anyone please tell me what exactly this means? What does casting a void pointer onto a constant as in the above case, signify? Thanks. | |
Re: You could also try Qt: You can get the library here:- [url]http://qt.nokia.com/products/[/url] | |
Re: First: Its never a good idea to include a c/cpp file. This is better:- say file.h is the header. The corresponding C++ file will be file.cpp So, you include the header file and the C++ file is included in the project. The files are as follows: 1)main.cpp [CODE]#include <iostream> #include … | |
Re: You had declared it as string variables. In C, strings are nothing but NULL terminated character arrays. You can overload the == operator(since you have already used the string class) OR you could write the 2D string as: char [len][len]; // len in const and the 1D string as char[] | |
Re: How about this: let the number of lines you counted be "N". Now, do this: [CODE] // advance to last 10 lines. while (count != (N - 10)) { char c = file.get(); if (c == '\n') count++; } [/CODE] | |
Hello. i wrote a program to do the following: [B]Given two strings S1 and S2. Delete from S2 all those characters which occur in S1 also and finally create a clean S2 with the relevant characters deleted. [/B] This is what i tried: [CODE] void trimString() { char s1[] = … | |
Re: @OP [CODE] #include <stdio.h> #include <stdbool.h> #include <string.h> /* This function is fine */ bool palindromeCheck (char str1[], char str2[]) { int i=0; bool equal; while (str1[i] == str2[i] && str1[i] != '\0' && str2[i] != '\0') i++; if (str1[i] == '\0' && str2[i] =='\0') equal = true; else equal … | |
Hello. Well, for creating linked lists, i always use 2 pointers: one for beginning and one for the end of the list. Is this OK? Or am i required to have just a single pointer pointing to the beginning of the list and then traverse everytime i need to insert? … | |
Re: Check the other thread. And mark this thread as solved. Both have the same question. | |
Re: @OP Data Structures using C/C++ by Aaron M.Tenenbaum is pretty good. Algorithms and Data Structures - Niklaus Wirth (i have not gone through this one) | |
Hello. i was trying to solve this problem. [B]Given an array of size N in which every number is between 1 and N, determine if there are any duplicates in it.[/B] Well, what i did is, use an array called present, to flag the elements ie: [CODE] for (i = … | |
Re: Try this: [CODE] /* let n be the input variable */ while (n != 0) { num = n % 10; // gives the last digit arr[i++] = num; // store result in an array n /= 10; } /* print the array. You get the first output. Print it … | |
Hello. im having a little problem with file inclusion. im getting the following errors: error LNK2005: "long * addresses" (?addresses@@3PAJA) already defined in rere.obj fatal error LNK1169: one or more multiply defined symbols found My 3 files are as follows: mainFile.c [CODE]//Program for a singly-linked list #include "def.h" #include<stdio.h> #include<stdlib.h> … | |
Re: What help do you need? Please elaborate the problem and post the code where you're where facing problems. | |
Re: pls tell what is the difference between this two 1)taking a initger (or any [QUOTE]fundamental data type) pointer in the main function and then send it to some funtion as parameter. int *p; function(p); 2)taking a intiger and sending its adress to any function. int p; function(&p);[/QUOTE] No particular difference. … | |
Re: @OP You are recieving it as characters. So, when you type 1, its acutally taken as: '0' + 1 Use an integer array. or subtract '0' after taking input. i guess that was the problem. Does it solve it? | |
Re: Please see my next post. i posted it twice instead of editing. Sorry about that. | |
Re: @OP Try this: [CODE] #include <stdio.h> #include <string.h> int main(void) { char quit[10] = "q"; char buf[10]; fgets (buf, 100,stdin); if(strcmp(quit, buf) == 0) { printf("Quiting program\n"); } return 0; }[/CODE] For this purpose, i would rather do this : [CODE]if ( (key = getchar()) == 'q') { /* Your … | |
Re: Hmm, [CODE]if (key_pressed == 'q') return 0; [/CODE] That should do it. Also, try using a switch instead of the above. Makes code a little neat. | |
Re: Try making the process wait for an input character by using say getchar() or std::cin.get() Also, using system("pause") is not such a good idea: [URL="http://www.gidnetwork.com/b-61.html"]http://www.gidnetwork.com/b-61.html[/URL] | |
Re: What do you exactly mean by a password program? It can work on many levels. You can have a file that can keep track of passwords and which are encrypted too. So, it can be as complex as possible. Assuming you need a simple program which echoes a particular symbol … | |
Hello. i searched for the term relocatable code and this is what i found. Definition:[I][B]A code generated by an assembler or compiler, and in which all memory references needing relocation are either specially marked or relative to the current program-counter reading. [/B][/I] Can anyone please elaborate a little more and … | |
Hello Everyone. Well, i have really little experience in assembly. So, please excuse me if my question is very trivial. Well, i attended a course on programming the 8086 and we used the MASM assembler, and programming which, we always used this: [CODE] .model small [/CODE] i never understood exactly … | |
Can anyone please explain why a self reference on a structure is allowed, but not a variable of that type? This is what i mean: [CODE] struct node{ int a; struct node *n1; }; /* This is allowed */[/CODE] [CODE]struct node { int a; struct node n1; }; /* But … | |
Re: Yes. The problem is in mixed.h Just put a ';' after the class declaration and it will work. [CODE]#include <iostream> // for ostream, istream using namespace std; class Mixed { friend Mixed operator+(const Mixed& f1, const Mixed& f2); friend Mixed operator-(const Mixed& f1, const Mixed& f2); friend Mixed operator*(const Mixed& … | |
Hello, [CODE] #include <stdio.h> int main(void) { const int j = 2; int i; switch (i) { case 1:break; case j:break; default:break; } return 0; }[/CODE] i tried executing the above code, and i got the following error: [B]error: case label does not reduce to an integer constant[/B] Well, since … | |
Hello, im trying to write a recursive algorithm to generate the following binary sequence. ie basically: for 3: 000 001 010 011 100 101 110 111 i tried the iterative method, it works fine. this is what i did: [CODE]for (i = 0 to pow(2, n) ) { //generate the … | |
Re: This might help: When you are comparing two strings(char arrays), use an strcmp() as follows: [CODE] if (strcmp(str1, str2) > 0) { /* Then str2 comes first alphabetically */ } else { /* str1 comes first alphabetically */ }[/CODE] eg: [CODE] printf("%d", strcmp("Hello", "Zye")); /* Prints -1 */ printf("%d", strcmp("Hello", … | |
Hello. im quite new to Trees. i have been practicing with Binary Search Trees. Well, here the way of building a tree is just comparing a value with the current node and deciding where the new value is put. i mean: say 3 4 1: 3 goes first then 4 … | |
Hello. Can anyone please explain why the following code is not producing any runtime error? [CODE]int a[] = {1, 0}; printf("%d", a[-1]); [/CODE] PS:im using VC++ 2008. Thanks. | |
Hello. im having a small problem creating a tree. im not sure where im going wrong. Can anyone please help? Thanks. Here is the code: [CODE] #include <stdio.h> #include <stdlib.h> struct tree_el { int val; struct tree_el *right; struct tree_el *left; }; typedef struct tree_el node; void printout(node *tree) { … | |
Hello. im having a small problem creating a tree. im not sure where im going wrong. Can anyone please help? Thanks. Here is the code: [CODE] #include <stdio.h> #include <stdlib.h> struct tree_el { int val; struct tree_el *right; struct tree_el *left; }; typedef struct tree_el node; void printout(node *tree) { … | |
Hello. Can anyone please tell me if there are any sites where i can practice programming? i mean sites like TopCoder, SPOJ, CodeChef. But i needed a site where there is an explanation for problems(so that i can understand the basic algorithmic concepts) and then go on practicing it. i … | |
Re: >>>i dont have visual studio on my computer at home b/c it is really slow and old Try using online compilers like ideone: [url]www.ideone.com[/url] | |
Hello. For 2D matrix multiplication, i tried a new method, which uses only 2 for loops. (im basically using a 1D array to access the elements). Here is the code: // Mutiplication.cpp : Defines the entry point for the console application. // [CODE]#include <stdio.h> int main(void) { int a[] = … | |
Hello. i wanted to generate the following series(pattern). [B]The captain of TITANIC is a mathematics freak. He has recently been given a problem that he is unable to solve. And he has asked your help to solve it. There are n numbers in a given expression. X1 X2 X3 .... … | |
Re: With reference to threads, can anyone please tell me how i can download the POSIX threads library? Also, can i use it with VC++ ? i have VC++ 2008. | |
i needed to write a simple program to demonstrate the CRC mechanism in Networks. i needed a string of bools to be XORed with the polynomial. Well, i used <bitset> but that did not help much. So i just used a bool vector. This is how i proceeded. Here, when … |
The End.