- Upvotes Received
- 1
- Posts with Upvotes
- 1
- Upvoting Members
- 1
- Downvotes Received
- 0
- Posts with Downvotes
- 0
- Downvoting Members
- 0
23 Posted Topics
Re: What i understood from your question is that you are trying to read multiple strings in a single array..Then i think you need to take two dimensional array...see the code below: [code] #include<stdio.h> int main() { char arr[5][20]; int i; for (i=0;i<5;i++) { printf("\n Enter the string :"); fgets(arr[i],20,stdin); } … | |
Hi all, I want to find the size of proc file using C....can somebody help!!!! | |
Re: Okay....I think, the following prototype might help you... - I made this on Linux and compiled with gcc - 'test.txt' was in the same directory as my '.c' file [code] #include<stdio.h> #include<string.h> int main(void) { char buff[100]; FILE* fp_1; fp_1 = fopen("./test.txt","r"); memset(buff,0,sizeof(buff)); while(1) { if(fgets(buff,100,fp_1)) ; else { printf("\n … | |
Hi, I am facing a problem, I am accessing a text file through my C program to fetch some values. The problem is that, i want to check whether the text file is updated before opening it, as i want to save the time of opening the file again if … | |
Re: [code] for(i = 0; i < arraysize; i++) { [B]randno[i] = malloc(10 * sizeof(int)); [/B]// [B]TYPECAST THE OUTPUT OF MALLOC[/B] }arraysize = 100; // number of rows randno = malloc(arraysize * sizeof(int *)); // allocate array of pointers [/code] And one more thing to add, Always typecast the output of … | |
The man page of 'sscanf' says: "EOF is also returned if a read error occurs, in which case the error indicator for the stream (see ferror(3)) is set, and errno is set indicate the error" I am confused that what kind of read error may occur if sscanf is reading … | |
Re: The structure in wave.h is typedef'd as 'WAVE_FILE' and in your analyze.c you are using [code=c] WAV_FILE file; [/code] Don't you think its a typing mistake and should be WAVE_FILE file??? | |
Re: [code=c] int function(char *source) { /* add stuff here Note: do not use a buffer overflow*/ return 0; } void main(){ int x; x=0; if(function("...")) x=1; printf("%d\n",x); } [/code] | |
Re: malloc always returns starting address of the memory allocated so may be the line: [code] Queue q = (Queue)malloc(sizeof(Queue)); [/code] could well be replaced by [code] Queue *q = (Queue*)malloc(sizeof(struct Queue)); [/code] | |
Re: Well, i think, this might be a simpler way to solve your problem. I took an array of inetegers to be populated. [code] int main(void) { FILE *fp; char buff[100]; int i = 0; int var[100]; fp = fopen("./test.txt","r"); while(fgets(buff,sizeof(buff),fp) { for(i=0;i<strlen(buff);i++) { if(isdigit(buff[i])) { var[i] = buff[i] - 48; … | |
Re: Ya, there is syntax error as stated in the above post...Also i want to add that even if there is only one expression corresponding to an 'if' or 'else', try using braces, this eliminates the possiblity of any ambiguity or error in future and code becomes managable... if { /*Expression*/ … | |
Hello every one, I have a confusion regarding arrays and pointers, My question is: "Is array name a pointer (rather a constant pointer)"?? I feel the answer is 'yes' because we can use the de-referencing operator(*) with the array name, Also, because array name is a constant pointer so we … | |
Re: I have written some rough code, please modify according to your requirement: 1) For pattern A B C D E F G F E D C B A A B C D E F __F E D C B A A B C D E _____E D C B A … | |
Re: Firstly, saying things like 'why doesnt it work for me' does not help us understanding your problem, please specify what exactly is the problem.. | |
Re: "[B]When arrays are declared as function parameters then they are treated as pointers and not arrays[/B]"....I think this would help you out... | |
Re: One possible reason can be that 'func.c' is not in the same directory/folder as 'myheader.h' and if this is the case then either you can put the 'myheader.h' in the same directory/folder as 'func.c' [B]OR[/B] You can put the 'myheader.h' in some standard path where your turbo c compiler searches … | |
Re: [code] #include<stdio.h> int main(void) { FILE* fd; char buff[100]; fd = fopen("./test.txt","r"); fgets(buff,sizeof(buff),fd); //here the line from file comes to char array buff printf("\n%s\n",buff); return 0; } [/code] | |
Re: What exactly are you trying to do here?? [code] char CountMin[1]; CountMin[0] = "8"; [/code] storing string in a charachter?? | |
Re: Also fgets() takes 'number of bytes to be copied' as an argument, which is a very good practice as it never lets you in problems like 'buffer overflows'...Use of gets() is generally discouraged.. For further info: man fgets (if you are on linux) | |
Re: As per the data provided by you, everything seems fine so please post the complete code in flow.... | |
![]() | Re: [code] while (fscanf(inFile, "%s", str) !=EOF) /*Reads and displays the file*/ fclose(inFile); //[B]Why are you closing the file in mid of everything[/B] for( i = 0; str[ i ]; i++) str[ i ] = toupper( str[ i ] ); printf("%s\n", str); /* uppercase string */ return 0; } [/code] if … |
Re: An addition, Once you've got the 1st or 3rd line using fgets() in a buffer, just go the position where the integer value starts and read the value using sscanf() with %d format specifier.. Hope this helps... | |
Re: Ha ha ha.... That reminds me of my school days when i used to think "I wish some angel does my home work"....We are not here to solve assignments, are we? |
The End.