Omnimaga: The Coders Of Tomorrow
Welcome, Guest. Please login or register.
 
Omnimaga: The Coders Of Tomorrow
22 May, 2013, 09:06:37 *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   home   news downloads projects tutorials misc forums rules new posts irc about Login Register  
+-OmnomIRC

You must Register, be logged in and have at least 40 posts to use this shout-box! If it still doesn't show up afterward, it might be that OmnomIRC is disabled for your group or under maintenance.

Note: You can also use an IRC client like mIRC, X-Chat or Mibbit to connect to an EFnet server and #omnimaga.

Pages: 1 2 [3]   Go Down
  Print  
Author Topic: C Q&A Thread -  (Read 2839 times) Bookmark and Share
0 Members and 1 Guest are viewing this topic.
sammyMaX
LV4 Regular (Next: 200)
****
Offline Offline

Last Login: 19 May, 2013, 00:12:41
Date Registered: 18 April, 2011, 18:01:37
Posts: 192


Total Post Ratings: +7

View Profile
« Reply #30 on: 22 August, 2011, 23:11:46 »
0

Awww... whatever, it's not crucial to my program anyways.
Logged


Are you wondering who Sammy is? My avatar is Sammy.
   
sammyMaX
LV4 Regular (Next: 200)
****
Offline Offline

Last Login: 19 May, 2013, 00:12:41
Date Registered: 18 April, 2011, 18:01:37
Posts: 192


Total Post Ratings: +7

View Profile
« Reply #31 on: 23 August, 2011, 00:29:52 »
0

Here's another question I have:
To handle input in my program, I have made a

1
char input[500];
This means the input can only be 500 characters, but if I use fancier dynamic allocation methods this problem still remains: sometimes when I type, weird characters will be outputted in front of the useful text, only to be overwritten as I type more. I might type in "12345", and then have it suddenly turn into "12345[=$_L?<". As I type in more characters, they get overwritten into "123459843406", but more random symbols may pop up later. I really don't know what would be causing that to happen, because my string drawing function has already worked on other things, and I can't find anything wrong with the key detection code. Any ideas?
Logged


Are you wondering who Sammy is? My avatar is Sammy.
   
ExtendeD
Coder Of Tomorrow
LV8 Addict (Next: 1000)
*
Offline Offline

Gender: Male
Last Login: 20 May, 2013, 19:47:13
Date Registered: 02 January, 2010, 13:03:41
Location: France
Posts: 765

Total Post Ratings: +151

View Profile
« Reply #32 on: 23 August, 2011, 10:06:31 »
0

We would need the code snippet which fills up "input[] to be able to help you, the problem may be there.
Logged

ndlessly - Progress and insights on Ndless
Ndless / Hackspire - Third-party TI-Nspire development
calc84maniac
Epic z80 roflpwner
Coder Of Tomorrow
LV11 Super Veteran (Next: 3000)
*
Offline Offline

Gender: Male
Last Login: 20 May, 2013, 21:27:24
Date Registered: 28 August, 2008, 05:09:05
Location: Right behind you.
Posts: 2735


Total Post Ratings: +373

View Profile
« Reply #33 on: 23 August, 2011, 15:19:33 »
0

Could it be a problem with null-termination? You can't assume that a dynamically allocated buffer (or a fixed-size local buffer) will be filled with 0.
Logged

"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman
Tribal
Anti-Riot Squad
LV5 Advanced (Next: 300)
*
Offline Offline

Gender: Male
Last Login: 12 May, 2013, 02:02:17
Date Registered: 02 September, 2008, 22:38:51
Location: $0001
Posts: 237


Total Post Ratings: +13

View Profile
« Reply #34 on: 24 August, 2011, 03:23:45 »
+1

Yeah, it kinda sounds like a problem with null termination.  You should never assume allocated memory is clean, the safest bet would be to do a

1
2
memset(input, 0, bytes allocated);
after allocation and see if it still does it.
Logged
ExtendeD
Coder Of Tomorrow
LV8 Addict (Next: 1000)
*
Offline Offline

Gender: Male
Last Login: 20 May, 2013, 19:47:13
Date Registered: 02 January, 2010, 13:03:41
Location: France
Posts: 765

Total Post Ratings: +151

View Profile
« Reply #35 on: 24 August, 2011, 14:34:47 »
+1

Or use calloc().
Logged

ndlessly - Progress and insights on Ndless
Ndless / Hackspire - Third-party TI-Nspire development
sammyMaX
LV4 Regular (Next: 200)
****
Offline Offline

Last Login: 19 May, 2013, 00:12:41
Date Registered: 18 April, 2011, 18:01:37
Posts: 192


Total Post Ratings: +7

View Profile
« Reply #36 on: 26 August, 2011, 02:10:41 »
0

Yay, it works! Thanks again!
Logged


Are you wondering who Sammy is? My avatar is Sammy.
   
Tribal
Anti-Riot Squad
LV5 Advanced (Next: 300)
*
Offline Offline

Gender: Male
Last Login: 12 May, 2013, 02:02:17
Date Registered: 02 September, 2008, 22:38:51
Location: $0001
Posts: 237


Total Post Ratings: +13

View Profile
« Reply #37 on: 26 August, 2011, 03:42:02 »
0

Or use calloc().

I've never used calloc ever since I came across the post on cprogramming's discussion board:

Quote
malloc will return an uninitialized chunk of memory for you to use.
calloc ( clear alloc ) will attempt to initialize that chunk of memory to all bits zero.

Note that when I say attempt, I mean that this may not be possible so you shouldn't rely on it. Other than that the only difference is how they are called and how they are implemented. So in the end, which one you choose to use is a matter of preference.
ref: http://cboard.cprogramming.com/c-programming/20505-malloc-vs-calloc.html#post132635
« Last Edit: 03 September, 2011, 18:27:16 by Tribal » Logged
sammyMaX
LV4 Regular (Next: 200)
****
Offline Offline

Last Login: 19 May, 2013, 00:12:41
Date Registered: 18 April, 2011, 18:01:37
Posts: 192


Total Post Ratings: +7

View Profile
« Reply #38 on: 03 September, 2011, 16:37:45 »
0

I'm getting a weird problem creating arrays now. Here's the code:

1
2
3
4
5
int numInts1 = ceil(operationPos, 4);
int numInts2 = ceil((inputLen - operationPos - 1), 4);

int *in1 = (int*)calloc(numInts1, sizeof(int));
int *in2 = (int*)calloc(numInts2, sizeof(int));
Using the Eclipse debugger, numInts1 is what it's supposed to be, and same as numInts2, but the arrays in1 and in2 are always only one int long. Attached a screenshot of the debugger. (What it's showing means that the arrays are one int long, right? Otherwise I wouldn't know what's wrong with my program)


* problem.jpg (60.79 KB, 799x312 - viewed 108 times.)
Logged


Are you wondering who Sammy is? My avatar is Sammy.
   
sammyMaX
LV4 Regular (Next: 200)
****
Offline Offline

Last Login: 19 May, 2013, 00:12:41
Date Registered: 18 April, 2011, 18:01:37
Posts: 192


Total Post Ratings: +7

View Profile
« Reply #39 on: 04 September, 2011, 16:56:02 »
0

Never mind - got it all fixed. It turns out that Eclipse can't figure out what's an array and what's not when they are dynamically allocated. Just click on the variable and then "Display as an Array."
Logged


Are you wondering who Sammy is? My avatar is Sammy.
   
Scipi
Omni Kitten Meow~ =^ω^=
LV10 31337 u53r (Next: 2000)
**********
Offline Offline

Gender: Male
Last Login: Today at 08:41:00
Date Registered: 12 September, 2010, 08:35:24
Location: Lost Town
Posts: 1380


Total Post Ratings: +145

View Profile WWW
« Reply #40 on: 20 January, 2012, 04:14:48 »
0

How do you use the show_msgbox function?

I have the following code:


1
2
3
4
5
6
7
8
#include <os.h>

int main()
{
    void show_msgbox("Hello World", "Hello Omnimaga");
    return 0;
}

And it's not compiling with the error:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
Tom@AdmirableCoffee /c/Users/Tom/Desktop/Programs/Ndless/Hello_World
$ make
nspire-gcc -Os -nostdlib -Wall -W -marm -c main.c
main.c: In function 'main':
main.c:5:10: error: expected declaration specifiers or '...' before string const
ant
main.c:5:10: error: expected declaration specifiers or '...' before string const
ant
main.c:5:10: error: expected declaration specifiers or '...' before numeric cons
tant
make: *** [main.o] Error 1

Tom@AdmirableCoffee /c/Users/Tom/Desktop/Programs/Ndless/Hello_World
$
Logged



Spoiler for Things I find interesting:
Spoiler for AI Programming:
Spoiler for Historical warfare/Formations(Warning: Large images):
Phalanx

Testudo

Schiltron

Better version
Terico

Line

Square

Spoiler for Shameless advertising:

Spoiler for OldSig:
Imma Cat! =^_^= (Make this an emoticon!)





Spoiler for IMPORTANT NEWS!:
Late last night, Quebec was invaded by a group calling themselves, "Omnimaga". Not much is known about these mysterious people except that they all carried calculators of some kind and they all seemed to converge on one house in particular. Experts estimate that the combined power of their fabled calculators is greater than all the worlds super computers put together. The group seems to be holding out in the home of a certain DJ_O, who the Omnimagians claim to be their founder. Such power has put the world at a standstill with everyone waiting to see what the Omnimagians will do...

Wait... This just in, the Omnimagians have sent the UN a list of demands that must be met or else the world will be "submitted to the wrath of Netham45's Lobster Army". Such demands include >9001 crates of peanuts, sacrificial blue lobsters, and a wide assortment of cherry flavored items. With such computing power stored in the hands of such people, we can only hope these demands are met.

In the wake of these events, we can only ask, Why? Why do these people make these demands, what caused them to gather, and what are their future plans...

Spoiler for Misc:


Spoiler for Goosed stuff:
FUSION-TIME GO!
Runer112
Anti-Riot Squad
LV10 31337 u53r (Next: 2000)
*
Offline Offline

Gender: Male
Last Login: Today at 05:42:54
Date Registered: 02 July, 2009, 06:38:05
Posts: 1679


Total Post Ratings: +492

View Profile
« Reply #41 on: 20 January, 2012, 04:34:54 »
0

Lose the "void" since you're calling the function, not declaring it. As far as making sure you're calling the function with the proper arguments, I can't help you there because I don't know anything about device-specific C development.
Logged
Scipi
Omni Kitten Meow~ =^ω^=
LV10 31337 u53r (Next: 2000)
**********
Offline Offline

Gender: Male
Last Login: Today at 08:41:00
Date Registered: 12 September, 2010, 08:35:24
Location: Lost Town
Posts: 1380


Total Post Ratings: +145

View Profile WWW
« Reply #42 on: 20 January, 2012, 05:01:10 »
0

It works. Thanks Cheesy

I honestly feel I should hit myself over the head hard for something so obvious Tongue
Logged



Spoiler for Things I find interesting:
Spoiler for AI Programming:
Spoiler for Historical warfare/Formations(Warning: Large images):
Phalanx

Testudo

Schiltron

Better version
Terico

Line

Square

Spoiler for Shameless advertising:

Spoiler for OldSig:
Imma Cat! =^_^= (Make this an emoticon!)





Spoiler for IMPORTANT NEWS!:
Late last night, Quebec was invaded by a group calling themselves, "Omnimaga". Not much is known about these mysterious people except that they all carried calculators of some kind and they all seemed to converge on one house in particular. Experts estimate that the combined power of their fabled calculators is greater than all the worlds super computers put together. The group seems to be holding out in the home of a certain DJ_O, who the Omnimagians claim to be their founder. Such power has put the world at a standstill with everyone waiting to see what the Omnimagians will do...

Wait... This just in, the Omnimagians have sent the UN a list of demands that must be met or else the world will be "submitted to the wrath of Netham45's Lobster Army". Such demands include >9001 crates of peanuts, sacrificial blue lobsters, and a wide assortment of cherry flavored items. With such computing power stored in the hands of such people, we can only hope these demands are met.

In the wake of these events, we can only ask, Why? Why do these people make these demands, what caused them to gather, and what are their future plans...

Spoiler for Misc:


Spoiler for Goosed stuff:
FUSION-TIME GO!
Pages: 1 2 [3]   Go Up
  Print  
 
Jump to:  

Powered by EzPortal
Powered by MySQL Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Powered by PHP
Page created in 0.277 seconds with 30 queries.
Skin by DJ Omnimaga edited from SMF default theme with the help of tr1p1ea.
All programs, games and songs avaliable on this website are property of their respective owners.
Best viewed in Opera, Firefox, Chrome and Safari with a resolution of 1024x768 or above.