- Strength to Increase Rep
- +4
- Strength to Decrease Rep
- -1
- Upvotes Received
- 14
- Posts with Upvotes
- 13
- Upvoting Members
- 9
- Downvotes Received
- 1
- Posts with Downvotes
- 1
- Downvoting Members
- 1
Re: You said "founded some errors" ... what did you find? I recommend adding some debug code, for example, to print or check validity of the entire linked list after every operation. | |
Re: That doesn't look like any C code I've ever seen. Wrong forum? | |
Re: Did you want to access the first integer in a string? or the first character in an integer? :-) How about the first integer in an array of integers?[CODE] int myarray[10] = {1,2,3,4,5,6,7,8,9,10}; printf("%d\n", myarray[0]); printf("%d\n", *myarray); printf("%d\n", myarray[5]); int *p; p = myarray; printf("%d\n", *p++); printf("%d\n", *p++); p = … | |
Re: Your original code was pretty good, but it does not change the value of "i" (i/10 doesn't do anything). It should be i = i/10 or i /= 10 (which is not as readable). printf() needs a newline "\n" in it. Also the function should return immediately when a match … | |
Re: The problem is not the malloc() statement, but in some other code which is corrupting the heap (= the space owned by malloc()). I would run the code in the debugger, but I can't because it isn't complete; do that if you can. If that isn't feasible, you can strip … | |
Re: I do not have the same compiler, but ... Each user-configuration (equivalent of Visual Studio .proj project file) has an option to disable the default path. Make sure the equivalent option is set correctly for your compiler. The message is not complaining that it can't find the file, it is … | |
Re: The proposed solutions are limited to integers on the input, about making the maximum input value approximately 1111111111, which (interpeted in binary) is 1023. As homework, that would be a "C" grade. A better solution would be to read the input as a string, accepting up to 32 characters, where … | |
Re: Try something like this: [CODE]x = low_number + (high_number - low_number) * (rand() / RAND_MAX) / 2.0;[/CODE] If you need more help, follow the policy of this forum, by writing some code yourself, and do not continue to ask for help without showing any effort on your part. | |
Re: 6-byte alignment is rare, I assume you want a generic reply. It could depend on integer divide, which always truncates (never rounds). Avoid negative numbers by using unsigned. The first problem is the length of a pointer, which can be up to 64 bits long. Here is a generalized example[CODE] … | |
Re: If you are programming in C++ you should not be writing your own linked-list code. There are a number of built-in or free container classes available for that purpose. Writing your own linked list (except to learn why you should not do it), is a waste of time since the … | |
Re: Just like if you were doing it on paper, you need to remember the numbers that were entered, and then process them after you have all of them. So you need some kind of a container (such as an array). Use one loop to enter the data into the container, … | |
Re: sizeof() is not an issue if you use ->next as recommended above, however, here are some details: 1) sizeof() is returning the number of bytes you used (4 + 15 + 4 + 4) = 27, but the compiler rounds up to a multiple of 3, 8, 16, or 32, … | |
Re: Read the forum rules, you are not allowed to ask other people to do your homework for you. | |
Re: You should solve the other (winsock library) problem. Loading the library dynamically causes all kinds of "weirdness", leading to unreadable and hard-to-maintain code. The typedef would be something like [CODE]typedef __stdcall struct hostent * (*)(const char *) p_gethostname;[/CODE] The macro name DECLARE_STDCALL_P suggests __stdcall may be appropriate. | |
Re: memcpy seems to be doing exactly what it was asked to do, ie. copy exactly 3 characters, 'b' 'i' 't', on top of a buffer which already contains 5 characters, 'b' 'b' 'i' 't' '\0' (note the null terminator). Only the first 3 characters are changed. To include the terminator, … | |
Re: Storing a string as an integer (array element) does not work here [CODE] taMsgOut->data[6] = (Uint32)Test_Date; [/CODE] for 2 reasons (a) casting a string pointer to an int will transmit the pointer, but not the actual string (that the pointer points toward), resulting in garbage, or worse. (b) the 4-byte … | |
Re: [CODE] for (int i = 0; i < strlen(line); i++) { line[i] = transform(line[i]); } line[i] = '\0'; // Bug: this line is missing string strLine = line;[/CODE] | |
Re: Assuming you have a C compiler for a DLX (whatever that is), this is trivial, since most C conpilers (all the ones I have ever seen) have an option to save the assembly language output to a file. This takes advantage of the way many compilers are written, ie. they … | |
Re: One of the rules on this site is: Do not post homework problems expecting a quick answer without showing any effort yourself. The posted code does not show any effort toward creating a 1D array. | |
Re: One of the rules on this site is: Do not post homework problems expecting a quick answer without showing any effort yourself. What do you have so far? | |
Re: Older compilers and linkers would allow you to "clobber" the compiled-in strings, but newer compilers discourage it. It is not portable, but more important, it invites viruses since there is real code stored near the compiled-in string, which could be modified by overrunning the end of the array (referred to … | |
Re: How about running the code in a debugger? (What compiler is it?) Other hints: line 61 reads one character. Line 64 stateCode[3] is beyond the end of the array. Line 64, "==" will never be true, use !strcmp(). | |
Re: This program is well organized, a good example for others using this forum. It has readable field names (such as "address"), and short, well defined functions that can be improved later without rewriting everything else. And I don't see any errors in the logic. It makes assumptions (array sizes, etc), … | |
Re: I just answered this question in another thread, the answer was, essentially, "go to a bookstore, and buy a good book". Look at the books in person (as opposed to online) and pick one that explains the topics in a way that you can understand. Maybe that could be added … | |
Re: I recommend going into a large bookstore, or one which specializes in "Technical books". Check the index of the "Advanced C programming" books, until you find an book with a whole chapter on signals, that also makes sense to you. If no bookstore is available, walk into someone's office that … | |
Re: The code is cut off at the end, but I don't see a problem. Try something simple, like below, and get it to work, before adding complexity. Also, use a short input file, with 4 lines in it, to start with, and add more lines after you get it working. … | |
Re: scanf is a function, not a variable, there should not be an = equal sign scanf=(something), if should be scanf(something); | |
Re: Since the number must be both even and a multiple of 7, it must therefore be a multiple of 14, [CODE] I = (I+13)/14; /* integer math rounds down */ I = I * 14; [/CODE] I put the statements on separate lines, for convenience in the debugger. | |
Re: The assignment says to allocate in the function, and free() it in main. [CODE] void get_days_in_month(int **days, int year) { int *array = malloc(sizeof(int) * 5) ; /* Set the output variable */ *days = array ; /* do not increment either pointer (days or array) */ array[0] = 31 … | |
Re: Trivial if the arrays are the same size. [CODE] int array1[10][100]; int array2[10][100]; array2 = array1; [/CODE] |