csurfer 422 Posting Pro

Well one advantage of that remote as I see is that channels wont be changed much often... Who would want to touch a slimy remote again and again...;) and ya nice list of ten things we could do without William Hemsworth.

csurfer 422 Posting Pro

Nice post there tux4life.

Just adding one more little information which is I know is very simple but just in order to complete the thread...:)

Every string manipulating function like strcpy strcmp etc take in the starting address of the string as input,so here as we are using character array to store the string we need to pass its starting address.
Therefore
char name[20]'s starting address is address of name[0] which can be written as &name[0], but as you know for an array
&array[0] = array,
so we just pass in the name of the array when ever we need to pass its address.

And even when we write something like

printf("Hello there !!!");

Some memory is allocated internally for storing the string "Hello there !!!" and its starting address is passed on to printf.Therefore

printf("Hello there !!!");

is almost similar to

char array[20]="Hello there !!!";
printf(array);
csurfer 422 Posting Pro

The code is not only weird its senseless. Firstly two pointers buffer and i manipulating the same char array so what it writes in the array in which condition is completely unpredictable it just depends on both the inputs.
And even by going by the function name "squeeze2" if the OP wants to squeeze the first or the second array then why so much redundant work it can even be achieved by inbuilt functions.

csurfer 422 Posting Pro

Well fptr.open(<filename>,ios::out|ios::app) helps you to append the data to the end of the file. But I don't think you can append it from the beginning of the file because the concept of append defines itself as adding contents to the end.

You can always do this :
1>Create another temporary file say temp.txt
2>Write the contents of your main file to this temp file.
3>Then open your main file in fptr.open(<filename>,ios::out);
4>Write into the file what ever you wanted to "append" earlier.Now as you know the entire file contents gets deleted and only the thing you just wrote is in the beginning of the file.
5>Re open your main file in fptr.open(<filename>,ios::out|ios::app) mode.
6>Write the contents of temp file to this file.

Even though a cumbersomely long process your objective is achieved.If someone knows a direct api for the above purpose I too would like to learn :).

csurfer 422 Posting Pro

Mistakes :

1> srand function is defined in cstdlib header and you haven't used it.
2> Your for looping is hopelessly gibberish (not making fun of your coding skills just an honest opinion about the loop structure ;))

Here is a better structured for loop :

// Initialize the necessary variables first.
for(i=0;i<n-1;) // i should run only till last but 1 element and you don't know how much to increment i
{
   x=i;y=i+1;m=1; // Temporary variables x and y to hold values m set to 1
   while(a[x]<=a[y] && y<n) // This loop finds out the length of the next sub array
   {
        m=m+1;
        x=x+1;
        y=y+1;
   }
   if(m>max) max=m;//If the length found > max then this value is maximum
   if(m>1) // Print sub array only if length > 1
   {
        // Printing the sub array where starting index is i and ending index is y
        for(j=i;j<=x;j++) cout<<a[j]<<" "; 
        cout<<endl<<endl;
   }
   i=i+m; // Increment i with the sub array length
   // Above step reduces the looping and increases efficiency and also it prevents 
   // the printing and finding of sub array of sub arrays
   // That is in a sequence 1 2 3 4 5 it prints 1 2 3 4 5 and quits and not
   // 1
   // 1 2
   // 1 2 3 and all upto 1 2 3 4 5
   // Because even though they satisfy the condition they are not really required.
}

Now I suppose you have come to know what we expect …

csurfer 422 Posting Pro

@mrcniceguy : You are pretty old to this community 148 posts still asking for codes ??? SHOCKING !!!

csurfer 422 Posting Pro

Well use getline function. It advances the file get pointer to next line automatically.Or even you can look upon f.seekg() function.

csurfer 422 Posting Pro

Here is an algorithm for it :

//open a file using fstream objects say file and functions like file.open() in input mode
// Create a string variable which can act as a buffer for holding the values
while(getline( <file descriptor value>, <buffer object>)!=NULL)
{
int key;
string skey,value;
//extract string value of key into skey and convert it into integer using istringstream
//extract string value of key into value
//With the help of a new fstream object write into the file you want it to.
//erase the buffer for providing space for next input using file.erase() function
}
csurfer 422 Posting Pro

>A person who couldn't resolve this kind of error, wouldn't understand the explaination of Salem.

We all started at that stage itself and we are still learning here so its better not to talk lightly of someone,because we all lack something or the other.

And I would like to mark this in bold with all credits to jephthah :
"It's just the culture here is that we'd rather teach a person to fish than give them fish."

csurfer 422 Posting Pro

Look the first thing you need to do is to relax and look at your own code more care fully ok. The code I posted in my post #2 was just minute alterations to your code with few corrections and I had mentioned all the reasons of error too.

Now who told you that cla_pre is useless.It has its meaning which you had given in the first code and it has retained its meaning.cla_pre has meaning when temp points to all nodes from the second node till the last node. It looses its meaning only when tem is pointing to the first node,ie the first node is the smallest element and temp and cla_pre both point to it.Perhaps you didn't read my post #2 properly. All the mistakes have been rectified then itself.

Well this is your complete code with corrections applied and it doesn't give any errors.
(gives right output for the second set of records you posted too)

#include<stdio.h>
#include<stdlib.h>
struct student
{
    int com,com_use; //[com:Computer_grades] [com_use:Laboratory_grades]
    int num,total; // [num:Seat_number] [total:the sum of math and english grades]
    struct student * next;
};
struct classes
{
    char t; // [t:Class_Character]
    struct student * point;
    struct classes * next;
};
void sl_sort(struct classes **,struct student **); // The function of "Selection Sort"
int main()
{
    FILE *data;
    char temp;
    int first=1;
    int num_t,com_t,com_u_t;
    int stu_count=0;
    struct student *stu_head,*stu_pt,*stu_pre,*stu_cur;
    struct classes *cla_head,*cla_pt,*cla_pre,*cla_cur;
    stu_head=NULL;
    cla_head=NULL;
    data=fopen("final.txt","r");
    while ((fscanf(data,"%c %d %d %d\n",&temp,&num_t,&com_t,&com_u_t)) != EOF)
    {
        stu_pt=(struct student *)malloc(sizeof(struct …
csurfer 422 Posting Pro

> <conoi.h>
> getch() to look at the program output
Already Extinct.Try using newer standard coding styles.

>Hi,
>to answer this question you need to have some experience
>about php...
Even though relevant sounds a bit rude.It sounds like "Read my thread if you are educated enough".

csurfer 422 Posting Pro

@Sky Diploma : You didn't get him I suppose... He is directly asking for the codes. He is One of those highly honest lazy code hungry fellows... ;););)
Give him ten more links for great algorithms he will ask you a new one which will give him the codes directly.

Sky Diploma commented: Lol! +3
csurfer 422 Posting Pro

Mistake 1 : Put your codes inside code tags or else no one will care to look at it.

Mistake 2 : exit() is a function and it is defined inside cstdlib header with respect to c++ and you haven't included it in the headers so the error not defined in this scope.

csurfer 422 Posting Pro

We don't really need to define power.And we humans fear only the things which aren't understood,so may be the undefined power defines itself in this way itself to maintain a balance in nature.We don't even need to give it a name. So if given a thought "This undefined power itself is defining the universe in this very undefined way". So what ever we may call this power Science,Inter Atomic Force,XYZ,.............,God or anything else,its it's feel that we need to experience...

csurfer 422 Posting Pro

"Shawshank Redemption" go watch it now or else you'll miss out on a very good movie, The tag line "Fear holds you a prisoner,Hope sets you free" itself defines it...

csurfer 422 Posting Pro

@StuXYZ :

Several things from your question:
First the string part. You have many options (a) you can indeed use
insert but the method requires an iterator to define the position for insertion. (b) the easiest to use simply += e.g

char p='x';
std::string A("test");
A+=x;
// A is now testx

Make sure that the examples you give are correct because in the above code what you have stated is wrong and it would give rise to a compiler error stating that char variable x not declared.
Its either :

char p='x';
std::string A("test");
A+=p;
// A is now testx

or better and simple do this :

//char p='x';//Not at all required
std::string A("test");
A+='x';
// A is now testx
csurfer 422 Posting Pro

Fire Fox !!! Wooo !!! But also Chrome as GOOGLE is involved .... :)

csurfer 422 Posting Pro

So that leaves us no more ahead than NULL !!! We haven't generated truely random numbers .... !!! :(

csurfer 422 Posting Pro

>Isn't 16 *'s maximum in C ???
I have never seen maximal values of translation limits were defined in C docs.

Well I had seen it being limited in some early versions of cc gcc and all .Actually had read about them somewhere "Not quite sure though".So asked it here.But don't know how Ancient Dragon found out the limit,but 500 and 920 are quite surprising !!!

@Ancient Dragon : Can I get the link where you found that out ? Or atleast the method ? And what do you think is the limit for POSIX and C99 compliant gcc version?

csurfer 422 Posting Pro

For me First comes "A Beautiful Mind" and falling back just by an inch is "Shawshank Redemption".
The two most unforgettable movies I have ever seen.

iamthwee commented: If you haven't seen 'Good Will hunting' you'll enjoy that +21
csurfer 422 Posting Pro

Random numbers are so important that sometimes at some point we do feel "Are the random numbers really generated randomly?" and "Can such an important topic be really left to chance?".What do you guys feel is the answer to this?

csurfer 422 Posting Pro

Isn't 16 *'s maximum in C ???
I mean that *p,**p,***p.....

csurfer 422 Posting Pro

@NeoKyrgyz : Did your post add even an inch to what Salem had said ? Was that really necessary ? (Salem's post was the reason many others didn't post because it rectifies everything with respect to this thread.:) and nothing more could be added.)

csurfer 422 Posting Pro

"After reading all the above posts once" you will know your question itself has your answer.
1>Convert float to string.
2>Concatenate using srtcat or strncat as said by you or snprintf as said by Arkm.

When you know everything did you try to google out first?I think you lost your patience in the last step. !!! ;)

csurfer 422 Posting Pro

No what I have written is wright because assume the following condition :

1 -> 2 -> 3 -> D -> E -> .....

Now if you assume cla_start_count = 3 that is if first three nodes are in their correct positions and if you want to add the temp node in your hand after the third node then
head = 1
shift 1 : 1 -> 2
shift 2 : 2 -> 3

Now you are in the correct node to add the temp node.
Now
temp->link=3->link;
3->link=temp;
will cause the link to be
1 -> 2 -> 3 -> temp -> D -> E -> .....

So if you observed properly if cla_start_count is equal to n then you just need to move cla_add_at n-1 times from the start as cla_add_at=cla_add_at->link;

So for i>1 is perfectly right... Got it ? ;)

csurfer 422 Posting Pro

You have a problem with the whole program or just a part of it ? Because its really hard to scan through every part...

csurfer 422 Posting Pro

Try Google Scholar and Scribd.You will get whole lots of stuff...!!! In Scribd you can even download pdf format itself... :D

csurfer 422 Posting Pro

Well you get built in options for the things you have asked both in Dev-Cpp and also Code Blocks...Try them.

csurfer 422 Posting Pro

Every file ends with an EOF character.Find out what the functions which ArkM has stated does and use the above information and you are done.

csurfer 422 Posting Pro

Well if you can control the output of a random function then it wont remain a RANDOM function right ??? :D
Well you can always do this.First assume a variable "a" which is defined as follows :

1>a=Some random number from 1 to 19 (%20) generated by some random number generating method.
2>Place 0 in this block of array as array[a]=0.
3>Now your are sure that the array has one zero and also in a random place generated by computer itself.
4>Now go on with your for loop as above itself and just skip the loop when i==a.

And ya you have loads of threads here at daniweb to make the random function better.Just have a look at these threads it may help.

jephthah commented: if i tell you the secret, it won't be a secret! +10
csurfer 422 Posting Pro

Errors (from line 119) :

cla_pre=*cla_head;
while (cla_pre->next != cla_temp) //Error 1
{
cla_pre=cla_pre->next;
}
cla_pre->next=cla_temp->next;
if (cla_start_count != 0)
{
cla_add_at=*cla_head;
while (cla_add_at->next != cla_start)
{
cla_add_at=cla_add_at->next; //Error 2
}
cla_temp->next=cla_pre; //Error 3
cla_add_at->next=cla_temp;
}
else
{
cla_temp->next=*cla_head;
*cla_head=cla_temp;
}
cla_start_count=cla_start_count+1;
}
}

There are corrections needed after line 119.It should be like this (you can just delete everything from 119 onwards including 119 and add the below code):

cla_pre=*cla_head;       //Error 1handling start
        if(cla_temp!=cla_pre)
        {
            while (cla_pre->next != cla_temp)
            {
                cla_pre=cla_pre->next;
            }
            cla_pre->next=cla_temp->next;
        }
        else
        {
            cla_start_count=cla_start_count+1;
            continue;
        }                                                // Error 1 handling end
   
        if (cla_start_count != 0)                    
        {
             cla_add_at=*cla_head;
             for(i=cla_start_count;i>1;i--)          //Error 2 handling start
             {
                 cla_add_at=cla_add_at->next;
             }                                                           //Error 2 handling end
             cla_temp->next=cla_add_at->next;     // Error 3 handled 
             cla_add_at->next=cla_temp;
        }
        else
        {
             cla_temp->next=*cla_head;
            *cla_head=cla_temp;
        }
        cla_start_count=cla_start_count+1;
    }
}

Error 1:
You didn't handle the condition where temp could be the first node,so in that case pre would start from head and never get a condition where in pre->next=temp because in this case pre=temp.So segmentation fault.
Error 2:
Here you weren't moving cla_add_at in right way atleast not the correct number of times.
Error 3:
You need to insert temp node here.But look at what you were doing before this.You were doing something totally nonsense.

With these errors corrected its giving the right output.

csurfer 422 Posting Pro

I got how you are trying to generate the prime numbers but you have messed it up to a great extent.

>Assume another variable lim which has the maximum index of prime numbers stored in array p.That is if you have got 3 prime numbers p[1],p[2],p[3] then lim is 3 and a variable called flag which signifies divisible if 1 and not divisible if 0.
>Just after your

if (num<5)
for(j=1;j<=((num+1)/2);j++)
printf("%d,",p[j]);
else
{
for(j=1;j<=3;j++)
printf("%d,",p[j]);

step do this :

x=6;
while(x<num)
{
           flag=0;//Signifies not divisible
           for(i=1;i<=lim;i++)
          {
                      if(x%p[i]==0)
                     {
                               flag=1; //shows its divisible
                               break;
                     }
         }
         if(flag==0)
         {
                      p[++lim]=x;
         }
         x++;
}
//Print the array p[] from 1 to lim here and you are done.

Its just this much even if I follow your algorithm.You are just confused.Take time to view your code once and the optimized code given above.And ya put your codes within code tags from next time.

csurfer 422 Posting Pro

I suppose you are using some compiler like TC because if you try to do something like array[-1] in gcc then it gives a segmentation fault.
Actually the concept is like this.When you write a statement like

int array[10];

10 consecutive integer blocks are alloted in memory with name array which can be accessed as array. When you write array[-1] then it tries to access an integer block before the memory allocated for array.Hence is illegal memory access.Hence not a valid statement.

And

array[1] = *(array+1);

because as you know

array=&array[0]

,you can access the 2nd block of memory allocated for array or the [1]th block as array[1] or *(array+1) because

*(array+1)=*(&array[0]+1)

which means get the array starting address increment it by 1 so it will point to second block of memory then get its value by * operator.

tux4life commented: Nice explanation :) +8
csurfer 422 Posting Pro

Take input in an char array and swap the positions.Hold two pointers say i and j i pointing to 0 and j to last input character position.Swap arr and arr[j] and then i++,j--;then again swap until i=j.

csurfer 422 Posting Pro

Think this can help you a bit.

csurfer 422 Posting Pro

The most Honest Post I have ever seen !!! This person has directly shown us the places where we need to code for him. Wow !!! He is honestly saying "Look guys i have commented in places where you need to put in your codes,and better do it fast".:D This is hilarious !!!

csurfer 422 Posting Pro

Errors I found :

int cla_start_count=0,i;
cla_start=*cla_head;
while (1)
{
        if (cla_start_count != 0)
        {
             cla_start=*cla_head;
             for (i=cla_start_count;i>0;i--)
             {
                 cla_start=cla_start->next;
             }
       }
if (cla_start->next = NULL) // Error 
{
     break;
}

Error : Assignment operator instead of comparison operator.You need to use == and you have used =.

Apart from this the code runs fine without error but you have just sorted and left it as such. You haven't written the code for printing the sorted list.

csurfer 422 Posting Pro

It was you who started with the string.I would have used :

list<int> integer_list;
list<int>::iterator i;
for(i=integer_list.begin(); i != integer_list.end(); ++i){...}

instead.
for my work.Well you can get some help here.

Yes of course,use the indexes for traversal and other work.What else do you use it for by the way??? :?:

csurfer 422 Posting Pro

You can do this...

//header files
int main()
{
//variable declarations
while(1)
{
//write your program code here it keeps on looping
.
.
.
.
//Some condition to break the looping if user wishes
}
return 0;
}
csurfer 422 Posting Pro
csurfer 422 Posting Pro

You wont get codes here,but we will help you code.
Do this:
1)Take the two strings into a char array(Store those two strings).
2)Traverse through those strings and get the numeric values in that string separated by a "." character and store these values as another string.
3)Find a way to get the numeric value from this string.
4)Add it as adatapost has taught you (Good one there buddy ;)).
5)Print it and you are done.

csurfer 422 Posting Pro

I think you didn't understand what Ancient Dragon said.You are printing the array till 900 but the inputs may end at 10 itself right?
So take a variable say count inside while loop as:

count=0;
while (infile) {
	getline(infile, pd.name[i], ',');
	infile >> pd.age[i];
	getline(infile, pd.favourite_colour[i], ',');
        count++;
	i++;
}

And then print array only till count as:

for(int i = 0; i < count; i++){}
csurfer 422 Posting Pro

conio.h is an EXTINCT header file.And we don't even want to save it.
Daniweb has several discussions regarding not to use:

getch();
system("pause");

for looking at the output.
But instead to use:

cin.get();

You are doing nothing but printing a string here:

for(p = listA.begin(); p!= listA.end(); p++)
cout << *p << " ";

Instead try to get numeric value from it and manipulate it because you want to build a calculator remember?

csurfer 422 Posting Pro

Yes vmanes you are right. But the OP had to start somewhere so I thought this would be better to start with and later learning and bettering the code from his/her own mistakes.Even this could be a solution to start with :

while(f_ptr){....}

But best according to daniweb is to use this:

while(fgets(....)!=NULL){.....} //or to use
while(getline(....)!=NULL){.....}

Get more info here.

csurfer 422 Posting Pro

Well check out the uniqueness of the password because if numbers are used as passwords then in most substitution and some block ciphers you get the same encryption or decryption for two passwords. And the speed is ok I suppose 5000 chars per sec thats nearly 39 kbps.Well for this you need to check in with a network expert because the speed which we are talking about is not transmission speed its the pre-transmission work and is considered as a delay.

csurfer 422 Posting Pro

Well you don't even need to know the number of lines in the file.
Use this :

fstream f_ptr;
string str;
f_ptr.open(<filename>,ios::in);
while(!f_ptr.eof())
getline(f_ptr,str,<delimiter>);

This complies to your requirements when the fields are delimited by some value.

csurfer 422 Posting Pro

@gretty : Ancient Dragon is right its not efficient.

The above code works right ??? Then whats the problem ? Why isn't this thread marked solved ?

csurfer 422 Posting Pro

Your code doesn't involve any c++ concepts. It is completely a c code I should say.And I think you are getting confused the order of execution is :

printf("Enter Your Age: ");  // Executes 1st
age = getInt(IsValidAge);  // Executes 2nd
printf("Enter your driving test mark: "); //Executes 3rd
mark = getInt(IsValidMark);  //Executes 4th

And this code involves a more subtle concept called function pointers.Read this.

The code getInt is called first which in turn executes the function IsValidAge and IsValidMark in lines :

if(IsValid != NULL)
{
valid = (*IsValid)(num,ErrMes);
}

This is the call by function pointers.

csurfer 422 Posting Pro

Well what are you aiming your text encryptor to work for? It just depends on the application for which you are designing it for. More over the efficiency of working of your encryptor also matters.If its fast but not a good encoder then its a waste. And what type of encryption are you using? I mean the kind of cipher ?

csurfer 422 Posting Pro

Well do you know what exactly you are doing or what you want to do ?

FILE *fopen(); // Why this ?

And what are you expecting the computer to display when you are just opening the file and closing it ?

finput = fopen(pfile, "r");

if(finput==NULL) {printf("Error: can't open the file.txt\n");return 2;}
else {printf("File opened successfully.\n");}

fclose(finput);

And why so much complexity?

char pfile[80];
printf ("Type number of input (between 1 to 3): ");
scanf ("%i", i); // Error here in scaning (no &)
if (i = 1)
pfile == "pf1";
else if (i = 2)
pfile == "pf2";
else if (i = 3)
pfile == "pf3";
else
{printf ("Invalid Input, the number should between 1 to 3!!!");}
finput = fopen(pfile, "r");

The complete thing above can be done just by:

char pfile[80];
printf ("Type number of input (between 1 to 3): ");
scanf ("%i",&i);
sprintf(pfile,"pf%d",i);
finput=fopen(pfile,"r");