Search Results

Showing results 1 to 40 of 49
Search took 0.01 seconds.
Search: Posts Made By: vijayan121 ; Forum: C and child forums
Forum: C May 16th, 2008
Replies: 8
Views: 1,707
Posted By vijayan121
> i try to avoid copying anything than 2 pointers...
swapping pointers is easy; swap pointers to arrays just like you swap any other pointers.
#include <stdio.h>

void swap( int rows, int cols,...
Forum: C Oct 9th, 2007
Replies: 18
Views: 4,400
Posted By vijayan121
>> what function which is similar to stat that asks for a FILE* fildes rather than int fildes?
the function int fileno(FILE *stream); is part of both posix and single unix specifications....
Forum: C May 11th, 2007
Replies: 11
Views: 2,481
Posted By vijayan121
ostringstream stm ;
stm << "Total points " << points ;
MessageBox(hwnd, "You have bla bla", stm.str().c_str(), MB_OK);
Forum: C May 10th, 2007
Replies: 27
Views: 3,850
Posted By vijayan121
part of the reason for you confusion is that you are trying out code with a. sizeof of the element (int) happens to be the same as the size of a pointer on your implementation. b. there are just two...
Forum: C May 10th, 2007
Replies: 27
Views: 3,850
Posted By vijayan121
i think you are getting it wrong here. arr is not a pointer, it is the array (the 'block' as you called it). it is just that arr can be implicitly coverted to an rvalue; a pointer which points to the...
Forum: C May 10th, 2007
Replies: 27
Views: 3,850
Posted By vijayan121
right!

no, that is not right. when you write arr+1, that is an expression. so arr is converted to an rvalue of type pointer to element of array. the result of the conversion is a pointer to the...
Forum: C May 10th, 2007
Replies: 27
Views: 3,850
Posted By vijayan121
at the place where the definition of the array is visible, sizeof will give the size of the entire array. it is when you use the name of the array in an expression that it is treated as a pointer to...
Forum: C May 8th, 2007
Replies: 2
Views: 1,137
Posted By vijayan121
get to the command line terminal, cd to the directory and type
copy /A *.txt all.txt
you will get one big text file. i'm not sure about microsoft (or any other) word, but it should be possible to...
Forum: C May 8th, 2007
Replies: 6
Views: 1,315
Posted By vijayan121
probable reason is that you have failed to account for the null character that is appended by a call to fgets

on a normal call to close(), the protocol stack attempts to gracefully shutdown the...
Forum: C May 7th, 2007
Replies: 6
Views: 1,315
Posted By vijayan121
which is the socket api that you are using?


read one line of data by using fgets. read several lines by calling fgets in a loop and buffer the lines that are read into dynamically allocated...
Forum: C May 6th, 2007
Replies: 6
Views: 1,315
Posted By vijayan121
looks like a buffer overflow in the line

fscanf(fp, "%s %s %s %s",part1,part2,part3,part4);

the contents of the file is something that is not under programmatic control; a secure...
Forum: C May 6th, 2007
Replies: 2
Views: 2,001
Posted By vijayan121
processes do not have names; images (executable files) usually have names.
Forum: C May 6th, 2007
Replies: 23
Views: 3,413
Posted By vijayan121
ok, jerry. here is an implementation in C++; i have written it in C++ because a. i find it easier to explain bit-wise operations in code rather than in words. b. writing it in C would be me doing...
Forum: C May 5th, 2007
Replies: 23
Views: 3,413
Posted By vijayan121
see: http://homepage.mac.com/afj/lfsr.html
Forum: C May 4th, 2007
Replies: 12
Views: 2,333
Posted By vijayan121
why do you need a stack at all?

template< typename CHAR_TYPE>
inline bool is_palindrome( const CHAR_TYPE* begin )
{
const CHAR_TYPE* end = begin ;
while( *end ) ++end ;
while( begin <...
Forum: C May 4th, 2007
Replies: 24
Views: 9,664
Posted By vijayan121
yes, it is in seconds. and it is completely portable. (ANSI/POSIX)
you would need to write platform specific code if and only if you find that the resolution of CLOCKS_PER_SEC is too low for your...
Forum: C May 4th, 2007
Replies: 24
Views: 9,664
Posted By vijayan121
clock_t start, end;
double cpu_time_used;
start = clock();
/* whatever */
end = clock();
cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC;
Forum: C May 2nd, 2007
Replies: 13
Views: 1,715
Posted By vijayan121
just to reinforce what narue and salem have stated (more than once), here is a quote from someone who has dedicated a lifetime on doing things efficiently (and elegantly) in code:
"Premature...
Forum: C May 1st, 2007
Replies: 13
Views: 1,715
Posted By vijayan121
this would be about twice as slow as the original code.
and the code size would also be close to double the original.
(unless the compiler is smart enough to rewite it.)
Forum: C Apr 29th, 2007
Replies: 0
Views: 2,805
Posted By vijayan121
choose a random element from a sequence when
a. you do not know how many elements are there before hand
b. you want to make one single pass through the sequence
c. you do not want to use...
Forum: C Apr 29th, 2007
Replies: 17
Views: 17,981
Posted By vijayan121
see thread at
http://www.daniweb.com/techtalkforums/post345699.html#post345699
this fills an array, instead of printing out the random number; but the idea is the same
Forum: C Apr 29th, 2007
Replies: 17
Views: 17,981
Posted By vijayan121
you forgot to do
--required

in the for loop (line 14-16)
note: the loop could be made more efficient by adding if(required==0) break ;
Forum: C Apr 29th, 2007
Replies: 17
Views: 17,981
Posted By vijayan121
the parameter passed to the function is the number of ascending random integers to be printed.
modify line 24 to
generate_ascending_number(1024);
to print 1024 numbers.
Forum: C Apr 29th, 2007
Replies: 17
Views: 17,981
Posted By vijayan121
converting it to C is trivial; as you said it is only an algorithm

#include <stdio.h>
#include <time.h>
#include <stdlib.h>

void generate_ascending_rand( int N )
{
int available =...
Forum: C Apr 29th, 2007
Replies: 17
Views: 17,981
Posted By vijayan121
rand() could return a large value (RAND_MAX for instance); your program would then loop infinitely. you will have to do something like
if the value of ( RAND_MAX - largest_so_far ) is less than...
Forum: C Apr 27th, 2007
Replies: 2
Views: 922
Posted By vijayan121
the function(s) next_permutation in <algorithm> would generate the next permutation. you could call that repeatedly.
Forum: C Apr 27th, 2007
Replies: 4
Views: 1,288
Posted By vijayan121
not true. exceptions are designed with the idea that
a. you do not have to pay a high performance penalty in the event of there being no error
b. if there is an error, you are willing to spend...
Forum: C Apr 23rd, 2007
Replies: 4
Views: 1,037
Posted By vijayan121
enum { N=20, M=50 };
int(*a)[M] = malloc( sizeof( int[M] ) * N ) ; // C
int(*b)[M] = new int[N][M] ; // C++
Forum: C Apr 23rd, 2007
Replies: 1
Views: 2,596
Posted By vijayan121
yes, you define it as a global. however, there is a logical error in your declaration; the result of operator+ is a temporary variable; you should return the temporary by value, not reference.
what...
Forum: C Apr 20th, 2007
Replies: 1
Views: 736
Posted By vijayan121
template< typename T > inline void swap( T& a, T& b ) ; // declaration (function)
template< typename T, size_t N > struct array ; // declaration (class)

// definition of function
template<...
Forum: C Apr 20th, 2007
Replies: 9
Views: 1,674
Posted By vijayan121
char john[] = "john" ;
char mary[] = "mary" ;
int result = strcmp( john, mary ) ;
if( result < 0 ) cout << john << " should be before " << mary << '\n' ;
else if( result > 0 ) cout << john << "...
Forum: C Apr 19th, 2007
Replies: 8
Views: 2,386
Posted By vijayan121
if multiple reads can be used, the easiest is

#include <iostream>
int main()
{
int a, b, c ; char colon ;
std::cin >> a >> colon >> b >> colon >> c ;
std::cout << a << '\t' << b <<...
Forum: C Apr 19th, 2007
Replies: 8
Views: 2,386
Posted By vijayan121
and this is another (using boost)

#include <iostream>
#include <string>
#include <boost/tokenizer.hpp>
#include <boost/lexical_cast.hpp>

int main()
{
using namespace std;
Forum: C Apr 19th, 2007
Replies: 8
Views: 2,386
Posted By vijayan121
this is one way.

#include <string>
#include <iostream>
#include <algorithm>
#include <sstream>
using namespace std ;

int main()
{
Forum: C Apr 19th, 2007
Replies: 9
Views: 1,674
Posted By vijayan121
yes jerry, it would be very suitable for you. you would enter the struct (with name, year, doctor, illness as member variables) into an array and use a bubble sort (not the best sort unless you have...
Forum: C Apr 15th, 2007
Replies: 21
Views: 10,121
Posted By vijayan121
This problem is covered in detaill in Jon Bentley's Programming Pearls (Second Edition)
ISBN 81-7808-022-2 (Pearson Education)
see column 8 : Algorithm Design Techniques (pages 77-86)

Even if...
Forum: C Apr 13th, 2007
Replies: 4
Views: 3,267
Posted By vijayan121
The easier way is to divide by 10000 and take the remainder
int seed = num % 10000 ;
Forum: C Apr 10th, 2007
Replies: 2
Views: 1,103
Posted By vijayan121
bool verify_value( const char* cstr )
{
if( ( *csr == '-' ) || ( *cstr == '+' ) ) ++cstr ; // one leading + - is ok
while( cstr != 0 )
if( !isdigit(*cstr++) ) return false ;
...
Forum: C Apr 8th, 2007
Replies: 11
Views: 1,793
Posted By vijayan121
endl is a function

template<typename CHARTYPE, typename TRAITS>
basic_ostream<CHARTYPE,TRAITS >& endl(
basic_ostream<CHARTYPE,TRAITS>& stm )
{
stm <<...
Forum: C Apr 8th, 2007
Replies: 3
Views: 2,373
Posted By vijayan121
the parser for the command line seperates
arguments by looking for whitespaces. so if
the command line parameters do not have
whitespaces in them thins work fine.
putting quotes indicates that...
Showing results 1 to 40 of 49

 


About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC