406 Posted Topics
Re: @gretty : Ancient Dragon is right its not efficient. The above code works right ??? Then whats the problem ? Why isn't this thread marked solved ? | |
Re: After the end of file,the file is filled with null characters,so if you move the file pointer to a far off place and get a line from there then it inputs several '\0' characters into your string which when output by << doesn't show anything. NULL is a macro for … | |
Re: Well do you know what exactly you are doing or what you want to do ? [code=c] FILE *fopen(); // Why this ? [/code] And what are you expecting the computer to display when you are just opening the file and closing it ? [code=c] finput = fopen(pfile, "r"); if(finput==NULL) … | |
Re: Don't pin in the whole code every time.Just extract the erroneous part,that way you too will [B]dive deeper into the code[/B] and easy for us to analyze too | |
Re: To check the length of file you have done [code=c] while(infile) { infile >> x; sequence_length++; } [/code] After this the file pointer is at the end of file now you need to re-assign the pointer to the start of file.So before taking array input do [code=c]infile.seekg(0,ios::beg);[/code] And then take … | |
Re: [QUOTE=lexusdominus;884664]i want my program to pull out very specific small strings from files, but i dont know whats the best way of going about this. ive written a function that can get a specific line from a file, but its hard to keep track of where relevant data is. ive … | |
Re: It would be better if you divide that nary tree nodes in some hierarchical levels so that it would be helpful in deciding their positions in future. | |
Re: [B][COLOR="Red"]Don't Shout !!![/COLOR][/B] Writing things in capital letters is regarded as shouting...! So don't use it. And it may be urgent for you not for us so have patience. And indent the codes and use [URL="http://www.daniweb.com/forums/announcement8-3.html"]code tags[/URL]. | |
Re: [B]Does no one read the forum rules ??? At least a glance ???[/B] Please go through [URL="http://www.daniweb.com/forums/announcement8-3.html"]this[/URL] once.[B]Use Code Tags[/B]. And [COLOR="Red"][B]Please Use English[/B][/COLOR] here.[B]This is not a mobile chat zone[/B]. Your mistakes : [code=c] cout<< (rand() % 10) + 1<< " "; //creates random numbers from 1 to 100 … | |
Re: Hey its quite easy , 0x is hex right then ABC is calculated as follows : A * 16^2 + B * 16^1 + C * 16^0 i,e 10 * 484 + 11 * 16 + 12 * 1 2748 | |
Re: Well the objective is just to compare two strings right? Then even though strcmp can do the work wouldn't the usage as [code=c] #include<string> using namespace std; //within main string str1 str2; //inputs to strings as cin<<string if(str1==str2)//comparision [/code] Wouldn't the above implementation be more efficient? As we are using … | |
Re: Good work !!! But file access every time can be time taking,so,may be you can implement a sudoku board with linked list or a hash table so that traversal can get faster. | |
Re: This is one classical example of [URL="http://en.wikipedia.org/wiki/Recursion"]recursion[/URL]. I hope you know the rules of this problem. Here you have three stands say a b c where where n pegs are inserted into a from 1 to n numbering where 1 is on top and 2 below it 3 below 2 … | |
Re: Its better not to paste the questions given in other portals for [B]you to solve[/B] here for [B]us to solve[/B]. But since you have tried to code this is my view... >You are trying to find out factors of 2 and 5 for every number within a limit "num" for … | |
Re: [QUOTE]Qn 1. Write a C++ program that creates appropriate variables and performs the following actions: Gets the user to enter their name and year of birth. Adds the users names to one of two text files “wise.txt” or “strong.txt” based on their age at the start of this year. To … | |
Re: Wow !!! asking source code in Dani directly and that too at two places. I am [B][COLOR="Red"]SHOCKED !!![/COLOR][/B] | |
Re: Can I look at the module which generated this error I mean just that function. | |
Re: Thanks for the threads ! It feels just like [B]coming back home[/B] where we actually started ! :) | |
Re: Your program may be right and giving the right output too but try to use the inbuilt "C" functionality more.Because even after using recursion if you are doing so much work its nothing but "Crime Against Recursion".Try this... [code=c] #include<stdio.h> #include<string.h> #define MAXSIZE 10 void display(char c,int cnt,int i,char num[],int … | |
Re: iamthwee is right but if the intention of your tutor is to make you try such things by using programming constructs then you may try using linked list to solve your problem. | |
Re: Read Ancient Dragons post again. [QUOTE]Problems: the close parentheses is missing :-p[/QUOTE] You won't get the required output because strtok uses the character within " " in strtok(str," ") as the delimiter and uses it to cut the string rather than including it.This explains why the closing paranthesis is missing. … | |
Re: Well your question is not quite clear but you can always use fopen command with : “rb” Open a binary file for reading “wb” Create a binary file for writing “ab” Append to a binary file “rb+“ Open a binary file for read/write “wb+“ Create a binary file for read/write … | |
Re: "Please don't kill the codes,Pay them some respect " After all,they are "your" codes: [code=c] for(i=0;i { tot[i]=0.40*Assignment_average[i]+ Quiz_Average[i]*0.15+ participation[i]*0.10+Midterm[i]*0.15+ final[i]*0.20 avr[i]=tot[i]*100; } [/code] Complete their format at least.... Errors: >Usage of "&menu" in printf is not only syntactically wrong but also useless.Why do you want to print value of … | |
Re: You can create a new program for it where in you can declare a character array [code=c]char file[<file_size you want to set>];[/code] Read in the file into this array,so you are limiting the size of it,then delete the contents of the file and write the contents of the array back … | |
Re: Try adding your TC path to the "path" ENVIRONMENTAL VARIABLE in system properties.More info given [URL="http://www.daniweb.com/forums/thread175434.html"]http://www.daniweb.com/forums/thread175434.html[/URL] look at this thread. | |
Re: Well I really couldn't get what you meant but I will answer to the point I think you asked...k Well you can allocate two dimensional array as follows: [code=c] char **array; //Your two dimensional array int str_nos=10; //No of strings you want to have int str_len=60; //Maximum length of each … | |
Re: [QUOTE=sat4ever0606;834501][B]For inserting a node at the beginning y the foll code wont work?[/B] [code] struct node { int data; struct node *-next; }*head,*run,*ptr; [/code][/QUOTE] Hey i think you missed out on the erreneous "-" sign behind next in [code=c]struct node *-next;[/code] It should be [code=c]struct node * next;[/code] And also … | |
Re: Ancient Dragon has always got some great methods which come handy :) the above post by him is just superb. And ya if you want some predefined words as your file names for example in a business file like FINANCIAL, STRATEGIC and all you can feed it in the array … | |
Re: This is where you went wrong. In your program pointers min and max are there but are not pointing to any memory space at all.So when you try to access some memory as *min or *max they try to refer a memory not been allocated hence segmentation fault core dumped. … | |
Re: Being in this community for a while you very well know our answer "You are in a hurry solve it yourself" So stop posting "do quickly" and all from next time because we are here to learn and not take orders... As for your answer choose any problem in which … | |
Re: Well there are several methods , but I would go with the simplest... Assume that you take the dimension of nxn martix as the input from the user where user feeds in value of n. And array[][] is the one in which he feeds in the value. Just have another … | |
Re: Well to solve this look a the matrix format... when we give an input the maximum number within the matrix is input square... that is if input is n then the maximum number feeded into the matrix will be n suqare. Assume : Array = a[][]; Input = n; sq … | |
Re: I think the conversation is loosing track. You want to write a C program to write main function,take input in array and then sort it through some sorting algorithm and then run search through your assembly program right? Concentrate on that.Do this first: 1)Writing a main program and taking inputs … | |
We know #define statements are executed before the program is compiled (preprocessor directives) and so the characters used should have no other meaning (say keywords),but still the following statement is not possible and is erroneous why ? [code=c]#define int float[/code] How many passes would the preprocessor directives run for as … | |
Re: Here are some points which might help... 1)The program is perfectly alright and is running without any changes in it (In windows). 2)While running it through command prompt or in a shell it might cause some problems(may be i dont know) because of your argc and argv (why not just … | |
Re: switch is used to SWITCH between things or choices. Both, the developers of C language and also the people on this forum are quite witty...so take their wise words and do some research on the topic first before posting a question...thats the only way to learn things in a programming … | |
Re: What good would strstr do after you have tokenized the string??? Declare a string array and an integer array of some respectable size. Tokenize the string and assign every string formed to the indexes of string array.Now use the string array indexes and strcmp to find the repetition of a … | |
Re: [quote]Also i would like to know, In Unix what are the cases in which C program encounters a segmentation fault/core dump?[/quote] I didn't get your earlier question but segmentation fault in UNIX mainly appears in cases of illegal memory access.I mean problem with your pointers. | |
Re: [QUOTE=miniroselit;827384]whether there is c program implimentation forthe stable marriage problem? How can I extend this problem in a real life situation?[/QUOTE] Would you please state the problem please... | |
Re: Whats the problem???Take a file pointer as FILE *fp; fp=fopen("<path>","<permission>"); //error check | |
Re: [QUOTE=jenilgandhi;819041]plz help me to add two matrices using pointers..[/QUOTE] 1>Take two integer matrices say a[20],b[20],and a result matrix c[20],and two integer pointers pa and pb. 2>Assign the start address of arrays to these pointers. 3>Now if p points to a[0] then p+1 points to a[1] and you can even access … | |
Re: Make these changes in getData function: [code=c]int getData(int);[/code] change this to [code=c]int getData();[/code] ------------------------------------------------- [code=c]choice = getData(int);[/code] change this to [code=c]choice = getData();[/code] ------------------------------------------------- [code=c]int getData(int z) { z=0;[/code] change this to [code=c]int getData() { int z=0;[/code] ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- You cannot do this in menu function: [code=c]strcpy(theMenu[y].menuItem[LENGTH],{ " [1] Chicken … | |
Re: Here you are declaring the array within the function and then returning it to the main. This kind of things always do create problems as the local variable is tried to destroy as soon as the control comes out of that function. So its better always to create the array … | |
Re: Hey death_oclock is right. Not the other guy.Your question says details about many students so it should be of format: [code=c]student_name[<number of students>][<max length you would expect of a name>];[/code] And ya as per my suggestion you sincerely need to optimize your code.There are many redundant and waste lines too.Ex: … | |
Re: >Naure I used devc++ with the proposed changes but it has some problem with the recognition of timeval struct itself,and also wit the usage of tv.tv_sec.Any suggestions with regard to usage and also the good compiler to use??? | |
Re: Assuming that you want to print out or store the 8bit hex values of each character of the input string I am giving these guidelines. Firstly take the input into an array by name str[30] may be. Let the final array be: unsigned char foo[30][30]; Now convert every one of … | |
Re: [QUOTE=deepugtm;816217]I want to write a program that can run a file in my hard disk.For example,a test.bmp file is there in location D:\home\test.bmp,that program should open(like double clicking on it ) that file (test.bmp) and i can view the image contained in the file.[/QUOTE] For bitmap images (or images in … | |
Re: Hey assuming you want to sort your strings in order "smaller to larger" as you have been using the word "min" many times these are the things you need to do. 1>Correct every mistake nucleon has already stated. 2>Your selection sort function is a completely mess. You are comparing text[i] … | |
Re: Your program runs fine. Just make this small change and it will run. In your program it is: [code=c] for(k=1;k<=3;k++){ for(j=1;j<=5;j++){ for(i=1;i<=j;i++){ [/code] Change this thing as : [code=c] for(k=1;k<=3;k++){ for(j=1;j<=5;j+=2){ //Only change required... for(i=1;i<=j;i++){ [/code] In your code once a loop is finished the next set of runs for … | |
Re: Well this is not very efficient method but as you are using nearly 80 arrays it might come handy. Just do this : [code=c] for(i=0;i<80;i++) for(j=0;j<80;j++) Temp_array[j] = Array[j][i]; [/code] In the above mentioned way you will move every element in first row to temporary array.And now apply some method … |
The End.