Search Results

Showing results 1 to 25 of 25
Search took 0.01 seconds.
Search: Posts Made By: Radical Edward ; Forum: C and child forums
Forum: C Aug 19th, 2008
Replies: 4
Views: 1,798
Posted By Radical Edward
strtok ignores empty fields. Edward would recommend using another solution, like strcspn and some method of reading or copying a substring:

#include <stdio.h>
#include <string.h>

int main()
{...
Forum: C Aug 16th, 2008
Replies: 2
Views: 388
Posted By Radical Edward
break from the inner loop and then continue from the outer loop. If there's more to the body, you may need a flag or something similar:

while (condition) {
int nextIteration = 0;

while...
Forum: C Aug 15th, 2008
Replies: 6
Views: 2,500
Posted By Radical Edward
EOF doesn't have an ASCII value, it's required to be negative:

#include <stdio.h>

int main()
{
printf("%d\n", EOF);
return 0;
}
Forum: C Aug 14th, 2008
Replies: 2
Views: 438
Posted By Radical Edward
Not without storing the names as strings somewhere:

#include <stdio.h>

typedef struct {
int a;
int b;
} my_struct;

const char * const my_struct_fields[] = {
Forum: C Aug 10th, 2008
Replies: 10
Views: 2,544
Posted By Radical Edward
2x is multiplication; you can do it with 2 * x. The ^ operator exists in C, but not in the way that formulae use it. It means bitwise exclusive-OR instead of exponentiation. Turbo C supports the...
Forum: C Jun 12th, 2008
Replies: 2
Views: 843
Posted By Radical Edward
The result of the sizeof operator will give you the size in bytes. The result type is size_t, but printf doesn't support printing size_t except in C99. You can get around that by casting the result...
Forum: C Jun 12th, 2008
Replies: 6
Views: 735
Posted By Radical Edward
> If there is no way to calculate the size of RAW data..then wht would I do?
You should always have the size, either because you allocated enough memory to store the data, counted the data at some...
Forum: C Jun 10th, 2008
Replies: 2
Views: 394
Posted By Radical Edward
Compilers are just translators that turn readable source code into binary machine code that the computer understands. When a language is created, somebody writes a compiler in a different language....
Forum: C Jun 10th, 2008
Replies: 6
Views: 735
Posted By Radical Edward
If you want to make a completely unique copy of the data then you need to know the number of bytes as well as have a pointer to the data. Then you can allocate enough memory to the new pointer and...
Forum: C Jun 10th, 2008
Replies: 4
Views: 843
Posted By Radical Edward
Float code could mean a lot of things, can you be more specific?
Forum: C Jun 6th, 2008
Replies: 2
Views: 554
Posted By Radical Edward
> Let's say a=2, b=3; in for loop it will loop for 3 times rite?
Right. If you know how many times the loop will loop, you can take the loop away and simplify the world:

a = 2;
b = 3;...
Forum: C Jun 6th, 2008
Replies: 9
Views: 965
Posted By Radical Edward
When you want to print an address, you use the %p format modifier, and for extra safely cast the value to void*:

printf("%p\t%p\n", (void*)&i, (void*)&j);
Forum: C May 28th, 2008
Replies: 3
Views: 1,016
Posted By Radical Edward
> Which would be more acceptable to use?
It depends on a few things. The most obvious is that neither getch() nor system("pause") work everywhere.

getch():

Isn't mandated by the C standard,...
Forum: C May 17th, 2008
Replies: 2
Views: 771
Posted By Radical Edward
Edward isn't an expert on getch, but isn't the very definition of getch to read unbuffered input directly from the keyboard? Please post your code so that Ed can get a better idea of what you're...
Forum: C May 16th, 2008
Replies: 9
Views: 1,387
Posted By Radical Edward
> but you'd have to write a function to convert an entire string.
A lot of compilers also have this kind of function as an extension to the standard library:

#include <stdio.h>
#include...
Forum: C May 15th, 2008
Replies: 2
Views: 1,066
Posted By Radical Edward
> 2. What will be printed if the input is 100? Your grade is X you did great
This answer is not correct. Be sure to carefully check what the boundary number is for each case.

> 4. What will be...
Forum: C May 15th, 2008
Replies: 4
Solved: random number
Views: 870
Posted By Radical Edward
That's just a fancy way of doing this:

static unsigned seed;

int getRand(int a, int b)
{
srand(seed);
return a + rand() % (b - a + 1);
}
Forum: C May 15th, 2008
Replies: 3
Views: 3,244
Posted By Radical Edward
fgets reads a single line of characters, but fread reads a block of unidentified objects. fgets uses '\n' as a delimiter, but fread doesn't inspect any of the objects so it relies on a limit of the...
Forum: C May 13th, 2008
Replies: 14
Views: 1,589
Posted By Radical Edward
> If Im not clear on something, go ahead and ask.
What is it you want? Edward prefers to see the best in others, but if you only post the requirements of your program, at least one person is going...
Forum: C May 12th, 2008
Replies: 4
Solved: random number
Views: 870
Posted By Radical Edward
The same number or some numbers are being repeated? Your code works just fine when Edward tests it, but repeated numbers are expected unless you go out of your way to avoid them with something like a...
Forum: C May 8th, 2008
Replies: 4
Views: 3,788
Posted By Radical Edward
>I don't know where to allocate buffer...
Since you're passing the buffer by reference to string_concat, you should allocate the buffer in main, but if string_concat tries to make the string longer...
Forum: C May 7th, 2008
Replies: 4
Views: 774
Posted By Radical Edward
> I found the problem thanks to your example!
Woohoo! :) Just remember that sprintf and sscanf are exactly the same as fprintf and fscanf except they use strings instead of files. That's how Ed...
Forum: C May 7th, 2008
Replies: 4
Views: 774
Posted By Radical Edward
Does your sprintf call look like this?

#include <stdio.h>

int main(void)
{
int x = 123;
char s[4]; /* Enough room for "123" +1 for null character */

sprintf(s, "%d", x);
Forum: C May 2nd, 2008
Replies: 11
Views: 970
Posted By Radical Edward
You count the lines, but you don't go back and get the random line. Your function will always pick the last line in the file. This is what you want:

#include <stdio.h>
#include <stdlib.h>...
Forum: C May 2nd, 2008
Replies: 11
Views: 970
Posted By Radical Edward
The hard part is working out how to get a random line from the file when you don't know how many lines there are. One way is to read the file once and count the lines, then use that count to pick a...
Showing results 1 to 25 of 25

 


About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC