abhimanipal 91 Master Poster

Initial array is 1,2,3,4,5,6,7,8,9,10
After rotating it 3 times 8,9,10,1,2,3,4,5,6,7

abhimanipal 91 Master Poster

I think there is a logical error in the line 90-94. Let me use and example to explain the logic that should be used

Say you already have this lined list 10--20--30--40--50 and you want to insert 25. So it has to come between 20 and 30. So your while loop is something of this sort

while(current->data <data)     // This loop breaks at 30
{
     temp= current;
     current= current->next
}

When the loop breaks you have a pointer to 25 and 30
So now you have to place your new node between temp and current.You write code of this type
temp->link= new node
new node->link= current

I hope this clears your doubt

abhimanipal 91 Master Poster

Well to take input from the user there are many ways.
The easiest one is through command line arguments
The next one is through scanf() function. But this function is very dangerous, has lot of pitfalls. So you should avoid using it
Another way of taking user input is to use fgets. This is the safest way, but it is slightly more complicated

abhimanipal 91 Master Poster

When you create the current pointer in line 68, it is un initialized and points to some garbage location.
So when you use it in line 75 it goes into an infinite loop.
The solution to your problem is to initialize the current pointer when you create it

abhimanipal 91 Master Poster

I dont think you can make your char array dynamic.

abhimanipal 91 Master Poster

I do not think that your program is crashing....
This is what happens when you enter a char other than c.
Since the char is not c, the code goes to the default case, prints "press c to continue" then comes out of the switch scenario and wait for you to enter a char in response to getch()
If you want to give the user another choice to enter the char, you have to put the switch inside a while loop

abhimanipal 91 Master Poster

The return value for the read and write system calls is the number of char successfully read/ written.
Print that value and post the result here

abhimanipal 91 Master Poster

1. On line 57, strtok can be applied to char arrays and not chars

2. What kind of arguments have you supplied to main? Inspite of the fact that the compiler does not show you an error it is still a bad idea. main function should be defined either as
int main()
or
int main(int argc,char* argv[])

I think if you correct these 2 errors, your code may compile ....

abhimanipal 91 Master Poster

This is not a simple program.
First step would be to i/p and then o/p a string.
Then you should see if you can count the length of the string

My favorite book for C is "Let Us C" by Yashwant kanitkar
It teach C from the very basic and makes no assumption about the programming capability of the reader

abhimanipal 91 Master Poster

You could pass the input string as a command line argument

int main(int argc,char* argv[])
{
   printf("%s\n",argv[1]);
}

and then when you execute the program, you execute it like this ./test input string

I seriously think you need to read C from a book.

abhimanipal 91 Master Poster

According to your above post the function set_number_people is not defined to be a part of any class but yet when you call it, you use an object to call the function

abhimanipal 91 Master Poster

I think you need to do a bit of reading on C
Do you have any books, tutorials on C ?
If not there are some links available in this forum

abhimanipal 91 Master Poster

Yes take i/p in the char array instead of the string. The for the algorithm you want something of this sort

char arr[]= "input string"
char a= arr[0]
int count =1

loop i from 1 to the length of the string
if arr is equal to a then increase count
else
{
print a, count
a= a
count= 1
}

Did you get the algorithm ?

abhimanipal 91 Master Poster

Do you know what is a char array ?

abhimanipal 91 Master Poster

Why dont you try coding one function at a time, compile it.. see if it works then go on to the the next function. It will make life a whole lot simpler for you....
Also learn to format your code.It will be much easier for you to read it

abhimanipal 91 Master Poster
int main()
{
    float f=10.5678;
    printf("%f\n",f);
}

Now if you want more precision when you are printing the floating point number google for print and you will find ways to do that

abhimanipal 91 Master Poster

I am sorry I did not understand what is your problem ?I ran the code that you have posted for 10! and I got the answer. So what is the problem ?
These are the problems that I see with your code
You have not checked for overflow. If you enter as i/p a very large number then the factorial of that number will not be able to fit in the 32 bit (or what ever is the size of int in your system) and so the answer will be negative
You have used the non portable header file conio.h. Also use int main as opposed to just main

abhimanipal 91 Master Poster

Yes you can .... But you will have to figure out what are the ASCI values of the arrow keys
In future start a separate thread for your questions. Even if you feel that your question is related to the current discussion

abhimanipal 91 Master Poster

Same solution as the one suggested by AD but you could use a map instead of a vector

abhimanipal 91 Master Poster

Are you running your program from the Command Line ?Then a simple solution could be to run you program like this
./test >testfile

The > operator works on Linux. You might have to use a different operator for your system

abhimanipal 91 Master Poster

Also what are you expecting to get when you do sizeof(argv[2]). It will give you the size of a pointer. Is that what you want ?

abhimanipal 91 Master Poster

Also where is value for the variable emp on line 7 coming from ?

abhimanipal 91 Master Poster

In the accept data function, write a bunch of cin statements and when the user enters the data, write all of it to the file.

abhimanipal 91 Master Poster

I saw this same question on this forum a couple of days ago ...
Go thru the postings on this forum for last 2-3 days ....

abhimanipal 91 Master Poster

Well the lines array just has space to store the contests of the file. It does not have space to store the header.
Secondly in C if you want to assign a string constant to an char array you want to do something of this sort
char arr[]="This is a constant sting";
Thirdly you have messed up the syntax of strcat on line 53. Should it not be the other way around

You could print the data before sending it across. This will tell you if there is a problem with the send or your string processing

abhimanipal 91 Master Poster

Or some thing of this sort

int main()
{
    int a,b,c;
    scanf("%d\n%d\n%d",&a,&b,&c);
    
    printf("A is %d\nB is %d\nC is %d\n",a,b,c);
    return 1;
}

PS: Using scanf is a bad idea. The sooner you shift to fgets the better

abhimanipal 91 Master Poster

OK...Tell me what have you understood so far ?

abhimanipal 91 Master Poster

It will make a world of difference ....
In my posts above I told you there is a problem with the generate quiz function and then Aia pointed out another bug, have you made those 2 changes ?

abhimanipal 91 Master Poster

Are you not allowed to write the definition of the struct globally or you can write the definition of the struct globally and not make global objects ?
There is significant difference between the 2 statements. If you can write the definition globally, it will become much easier to code

abhimanipal 91 Master Poster

1. In the generate quiz function, the function return type is an int but you are trying to return an array.
2. The rest of the errors are coming because when you define the function readquestions, the compiler does not know that there exits a struct called as question...

Let me see if I can figure out how to solve this problem

abhimanipal 91 Master Poster

Why should system calls be avoided if you know your target environment ?

abhimanipal 91 Master Poster

An easy way would be to execute the ls command in your program...

abhimanipal 91 Master Poster

When you are checking to see how many chars have been printed via fprint use the condition <=0 insteaad of < 0

abhimanipal 91 Master Poster

Post the latest version of your code and let me see what is causing the error

abhimanipal 91 Master Poster

Post the latest version of your code man. The code posted above still does not contain the changes I told you to make earlier

Also use CODE TAGS.

abhimanipal 91 Master Poster

@Aranarth

Its a C- style approach. When we are program in C, all the variables have to be declared at the start of the function block

abhimanipal 91 Master Poster

In your scenario when ever the sender is sending some data, the last 2 chars will always be '\r' and the '\n'. So if I wanted to send ABC across the stream then I will send it across like this
"ABC\r\n"

In the receive function the code is reading the data bye by byte. Initially when the first byte is read, *ptr contains A. The code checks to see if A is equal to the \r. It is not, so it will read the next byte. B and then C are also not equal to \r. Then in the 4th read the *ptr will contain \r. So now the code reads another byte and checks if that byte equals \n. If it does then the code NULL terminates the data it has read. So when the buffer is returned from the receive function it contains ABC\0
Did this solve your question or do you have more doubts

abhimanipal 91 Master Poster

Generating random strings as a whole is tough ...
You could chose a random length and then chose random chars to fill that length

abhimanipal 91 Master Poster

@fxwebpage
Really thats your advise. If your code is not compiling then there is some error in your code !!!!

@melusim

Is this your code or did you copy paste from some where ?There are so so many errors in it

1. You have declared the sort function in the generatequiz function
2. In the read question function, in the second printf there is a spelling mistake. It should be structered_array[j].question as opposed to structured_array[j].question. You have made this mistake all over the function
3. In the generatequiz function you are trying to return a value when the return type of the function is void.
4. Dont define your struct inside the if block in the main function. Make it global
5. Include string.h
6. You have not used strtok correctly. Google for the correct syntax and apply the correct syntax here


I did not have the patience to investigate further.... There may be many more errors. Make all these changes and post the results

abhimanipal 91 Master Poster

Towards the end of your while loop(lines 83-84) you ask the user to chose between y/n but the variable that you have used for taking the input is an integer.
So what happens is when the user enters y, scanf sees that it has received an char but the variable it is going to use to place the input value is an integer so it does not do anything. The value of the variable e is the same value as before ie 1.
Then we come to line 70. we have a char in the input stream, but again scanf is expecting an int so we get a garbage value here. This procedure repeats itself infinitely.

abhimanipal 91 Master Poster

When you create the consumer thread, check the function call. The last parameter is s . It should be &i

abhimanipal 91 Master Poster

Suppose x contains the id number that you are looking for

ptr= list;
for(i=0;i<list->count;i++)
{
     // If you find a match then break;
     // Else do nothing
}

if(i==list->size)
// this means we went through the entire list and did not find a match
abhimanipal 91 Master Poster

WaltP's approach is much much more simpler ....

abhimanipal 91 Master Poster

Print the value of the file descriptor. When I printed the value I got -1.
One reason could be, as the article mentioned that I am unable to open the file due to lack of permissions.
Have you taken care of this issue ?

abhimanipal 91 Master Poster

Where is your attempt ?

abhimanipal 91 Master Poster

Did your problem get solved ?
If not where are you stuck now ?

abhimanipal 91 Master Poster

I normally use fread to read from a file.
But I am surprised to see none of you mentioned that method. Are there any known pitfalls in using fread ?

abhimanipal 91 Master Poster

Probably you could use a switch statement ????

http://msdn.microsoft.com/en-us/library/66k51h7a%28VS.80%29.aspx

abhimanipal 91 Master Poster

Tell me some thing why are combinations like bcanm allowed ?

PS: I dont think you have spent any time working on your algorithm

abhimanipal 91 Master Poster

I used this reference for setsockopt
http://msdn.microsoft.com/en-us/library/ms740476%28VS.85%29.aspx

According to this, setsock opt returms 0 for success. Change that part of code for your program.