abhimanipal 91 Master Poster

It appears line 6 needs to be changed as well, to the following:

int *nums = new int[SIZE];

It seems windows doesn't like to initialize such large arrays the way you were using, but this way will work fine.

This is a C forum ..... the operator new wont work with a C compiler

abhimanipal 91 Master Poster

What I mean try getting
the 2 prime number then
the 4 prime number then
the 8 prime number then
the 16 prime number then
the 32 prime number ....

See at which point your code fails

abhimanipal 91 Master Poster

Also post the typedef statement as well

abhimanipal 91 Master Poster

Quick question .... Are you planning to do some coding or is it just a theoretical project ?

abhimanipal 91 Master Poster

Did you try to go the exponential way ?

abhimanipal 91 Master Poster

For those starting out to develop apps for iPhone check out the Stanford University Lectures on the same. The lectures are pretty descriptive and contain lots of examples.
This the link for the 1st lecture. You can find out the remaining lectures from the related videos tab

abhimanipal 91 Master Poster

In the simulator of iPhone you cannot use most of the hardware features like accelerometer, location, camera,etc
Besides this the timing and performance results that you get out of a simulator will be very different from that of a real device.

So if you want to develop apps for iPhone it is recommended that you buy a macbook as well as iPhone.

Secondly Objective C is very different from C/C++ . Not only in terms of syntax but also the programming paradigm

abhimanipal 91 Master Poster

I ran your code and I got the correct o/p ie 10,4743

Where are you running your code ? Is it a specialized device ?
One thing you could do is dont jump straight to 10,000 Go there exponentially you know first calculate the 2,4,8,16,32,64 and so on

abhimanipal 91 Master Poster

To further develop AD's point

void func1(int** p)
{
        int x=20;
        *p= &x;
        printf("In pointer to pointer to int\n");
}



void func(int* p)
{
        int x=20;
        p= &x;
        printf("In pointer to int\n");

}

int main()
{
        int x=10;
        int* p= &x;
        func(p);
        printf("Value of x now is %d\n",*p);
        func1(&p);
        printf("Value of x now is %d\n",*p);

        return 0;
}

Maybe this example will clear your confusion

abhimanipal 91 Master Poster

im not really good in understanding, perharps posting the skeleton code might help? thanks

I have written the names of the functions that you need to use. If you search for each function you will get a ton of information.

abhimanipal 91 Master Poster

I dont know which more worse. Your ignorance about C or your stubbornness

abhimanipal 91 Master Poster

I am not sure how helpful this will be but check out this link

abhimanipal 91 Master Poster

Which kernel are you going to use ?

abhimanipal 91 Master Poster

Some more differences between C and C++
- C++ is more strongly typed than C
Using the most cliched in C++ we have to typecast the value returned by malloc

- I think the maximum length the variable can have in C is limited to 32 chars. What I mean is if the names of 2 variables are identical for the first 32 chars then they are treated same by the compiler

- Enums in C++ are a separate type

- Size of char constant is equal to the size of an int in C. But in C++ size of a char constant is equal to the size of a variable char

abhimanipal 91 Master Poster

Adding a little bit more information to gerard4143's post

Open the file (Use fopen for this)
Read the first line of the file and store it in a buffer (Use fread for this)
Go through the line and check if the name of the country appears in the file or not (Use strtok for this)
If a match is found send the contents of the line you just read to the client or send error

abhimanipal 91 Master Poster
struct temp
{
        char name[20];
};

struct temp t1[20];


int main()
{
        strcpy(t1[0].name,"abhimanipal");
        printf("%s\n",t1[0].name);
        return 0;
}

Maybe this will help you ....

abhimanipal 91 Master Poster

Objective C is quite different from C/C++ . It has lots and lots of quirks and it takes some time to get a grip on the whole thing


I am not trying to discourage you but just sharing my personal experience with you

abhimanipal 91 Master Poster

iPhone apps are usually written in Objective- C. You can use C++ in your objective -C programs but many of the common feature (constructors) are not allowed.
Overall it makes way more sense to develop in Objective- C for the iPhone/ iPad platform
Also iPhone does not support openGL. It supports openGL ES where ES obviously stands for Embedded Systems.

abhimanipal 91 Master Poster

What have you got so far ?

abhimanipal 91 Master Poster

Suppose you did not have a client server program and you had to make a simple username/ password application on that, how would you go about that ?
I have given you some hints in the code below. If you can fill out and complete this program then the extending it to client server is not tough

int main()
{
  char username[50]= "username";
  char password[50]= "password";

  char inputUserName[50];
  char inputPassword[50];

  // Make the user input the user name and password. Store it in the variables inputUserName and inputPassword respectively.

  //Now use strcmp to check if the entries entered by the user match the stored entries

   return 0;
}
abhimanipal 91 Master Poster

loop in line 70 is perfectly fine. I am using it becoz I need to find the last node in the list. So temp is running till it reaches last node.

Which loop is running infinitely?

The loop in line 70 is running infinitely that is why your program hangs. Your loop finds the end of the list but I dont see the end being used anywhere else in the function

abhimanipal 91 Master Poster

If you already have data stored on the array,how can you overwrite the sum after every 5 numbers?

I dont think you got the logic of the program that I wrote ....

abhimanipal 91 Master Poster

There are some tutorials posted at the very beginning of this forum ...
Check it out

abhimanipal 91 Master Poster

Have you heard of a little known website called as google.... Try it out.... You might like it
Here is what I found in just 0.23 seconds in this website

http://www.codeproject.com/KB/audio-video/madlldlib.aspx

abhimanipal 91 Master Poster

Your code is hanging because of the for loop on line 70.
From the looks of it I dont think you need the loop, so might as well delete it

But from a conceptual point of view I cannot understand why loop runs on infinitely

abhimanipal 91 Master Poster

This is how I would do it

int calculateAverage(int* a, int startPoint)
{
     for(int i= startPoint; i<startPoint+5;i++)
         //calculate the average and store it in sum

     return sum
}

int main()
{
     int arr[30]={1,2,3...30};

     for(int i=0;i<30;i++)
       average[i]= calculateAverage(arr,i);

    // Use some error handling for the cases when i becomes > 25
}
abhimanipal 91 Master Poster

Did you compile the code ?
Did you specify the name of the executable when you were compiling the code ?If not the default name is a.out

abhimanipal 91 Master Poster

This is a very brief answer to your question. For a more detailed answer try googling for it or wait for some one else to post it

When a function is called the context of the current function (the contents of the stacks, the values in the registers etc, the line number of the function call) is saved.
Then the control switches over to the piece of code which responds to the function you have called. If you call any other function from this function then the same process that I have described above happens. When the code reaches the return statement, then all the data stored previously is reloaded. If any value is to be returned from the function that value is put in the appropriate variable

abhimanipal 91 Master Poster

Can you provide some sample inputs and outputs ?
I am unable to understand what does palindrome and factorials have to do with the problem that you have posted

abhimanipal 91 Master Poster

You want to compare the theoretical complexity or the difference in execution time for each of the algorithms ?

abhimanipal 91 Master Poster

What have you got so far ?
Here is some thing to get you started
http://www.cs.cf.ac.uk/Dave/C/OLDC/subsection2_18_4_1.html

abhimanipal 91 Master Poster

Can you paste the content of the input file ?

Also I do not understand the rationale behind the number 80 ?Can some one explain why the size of the temp buffer is 80

abhimanipal 91 Master Poster

You can use string functions to get the substrings for each part of the time and convert it into integer to store in your variables.
Try this out:

ptrToYourStr = yourStr;
for(i = 0; i < 3; i++)
{
     time[i] = atoi(strndup(ptrToYourStr, 2)); //Taking the substring and converting to integer
     ptrToYourStr = ptrToYourStr + 2;
}
ptrToYourStr++;   //for the . before your fractionSeconds (last part)
time[i] = atoi(ptrToYourStr);  //Rest of the string is for fractionSeconds

Have a char pointer to your string "ptrToYourStr".
I have used the time integer array just to store the time values in the loop.

Cheers

What is the input given is 9:5:10? Your code will fail then. What Walt meant was something of this sort

while(not end of string)
{
    if(the char is not :)
    {
        time[j]+= (str[i]-'0')*power;
        power*=10;
    }
    else
    {
         power=1;
         j++;   
    }  
i++;
}
abhimanipal 91 Master Poster

Learn this basic rule of putting brackets .... This will make coding less of a night mare
Each time you introduce a new if/ for in a function press tab...
For example

void func1()
{
         for(;;)
         {
                  if()
                  {
                   
                   }
         }
}
abhimanipal 91 Master Poster

Your if on line 41... I think it should be

*(number + i)

To check if the char in question is a question mark write

if(*(number+i)=='?')

Running this loop the correct number of times is of essence

abhimanipal 91 Master Poster

Small hint if you are totally stuck ...
Use for loops

My personal advise is first try to sum up all the values in an array, then go for higher dimensions

abhimanipal 91 Master Poster

Go over each char of the string stored in foo.
If the char is a question mark, ignore it
Else keep it

Is the final product an integer or a char array ?

abhimanipal 91 Master Poster

What is the format of the numbers in your file ? Depending upon that you may have to do some string parsing ....

abhimanipal 91 Master Poster

The pseudo code for bubble sort is

for i=0 to i<n
{
    for j=0 to j<n-1
    {
        if a[j] > a[i]
           then swap
    }
} 

Check out the wiki link for bubble sort to get a more detailed explanation.

abhimanipal 91 Master Poster

c=product(a+2,b+1) will be expanded as
c= 2+2*2+1

abhimanipal 91 Master Poster

Can you explain the problem a bit more clearly ?
This is what I have understood so far. You have some shared memory. Thread 1 locks this memory up. so that when thread 2 access this region he find it locked ?
Is there any thing more to it ?

abhimanipal 91 Master Poster

The number 2 means that fgets will just read 2 chars from each line. You want to change that number to an appropriate size.

abhimanipal 91 Master Poster

Read about thread wait and thread signal methods

abhimanipal 91 Master Poster

What do you mean by "cannot access token[4] " ?

abhimanipal 91 Master Poster

You are closing the file, the first time you enter the else statement block. So the next time you come to the else block you will not be able to write anything to the file

Instead close the file when you come out of the while loop

abhimanipal 91 Master Poster

What have you done so far ?

abhimanipal 91 Master Poster

fskeek can often give un predictable results when being used with text files.
http://www.cplusplus.com/reference/clibrary/cstdio/fseek/

abhimanipal 91 Master Poster

In the code for case 1, Your second record will over write the first one, third will over write the second record and so one.
What you want to do is keep a count of how many records have already been inserted and then each time the user wishes to enter a new record, use fseek to skip ahead in that file

abhimanipal 91 Master Poster

I think the type cast has to be done before applying the shift operator. Here is an example to show why

int main()
{
    float f= 5.67;
    int x= (int)f<<2;
    printf("%d\n",x);    
    return 0;
}

If f is not typecasted before applying the shift operator then the code will not compile as shift operators cannot be applied to floating point numbers.
This code does compile and produces the answer 20

abhimanipal 91 Master Poster

Just think for a moment what you are doing.

In line 2 you are asking the computer to store a string in a char. So if I give the input as ABCDEFGH it will be stored in a char
Then in line 3 you are telling the computer to store that char in an array .

Is this what you really want ?