iPhone / iPod Touch SDK | Development Discussion SDK questions. A place for iPhone developers to post code snippets, discuss creating iPhone apps, and any other iPhone developing. |
|
03-23-2008, 04:25 PM
|
|
Livin the iPhone Life
|
|
|
|
I just made my first application!
Hey guys i just made my first application, its a calculator that runs in terminal, it adds, subtracts multiplies, and divides, it isn't much, but im excited!
Its in C, for some reason Objective -C doesn't look like a good starting point to learn development.
One question though, after i enter 6 + 6 or something, it logs out after, what command would i use to restart it?
Thanks, just had to share
|
__________________
Like what i said? Hit the Thanks Button!
1.83GHz MacBook 160GB HDD 1GB RAM
3.06GHz iMac 320GB HDD 2GB RAM
SEARCH BEFORE POSTING
|
The Following User Says Thank You to DoerrFan For This Useful Post:
|
|
03-23-2008, 11:27 PM
|
|
Green Apple
|
|
Join Date: Oct 2007
Posts: 44
Thanks: 13
Thanked 3 Times in 2 Posts
|
|
Cool, I would like to see your code... possible?
I am triying to learn ... wanna help me?
|
__________________
In Costa Rica Beaches w/ my unix box.
|
03-24-2008, 01:17 PM
|
|
Livin the iPhone Life
|
|
|
|
Quote:
Originally Posted by drunix
Cool, I would like to see your code... possible?
I am triying to learn ... wanna help me?
|
Sure, here:
Calculate.c
/*
* Calculate.c
* Calculator
*
* Created by Jon Makkinje on 3/21/08.
* Copyright 2008 All rights reserved.
*
*/
#include "Calculate.h"
#include <stdio.h>
#include <stdlib.h>
int calculate(int a, int b, char operator)
{
int result;
switch (operator) {
case '+':
result = a + b;
break;
case '-':
result = a - b;
break;
case '*':
result = a * b;
break;
case '/':
result = a / b;
break;
default:
printf("Unknown operator: %c/n", operator);
}
return result;
}
Calculate.h
int calculate(int a, int b, char operator);
main.c
#include <stdio.h>
#include <stdlib.h>
#include "Calculate.h"
int main (int argc, const char * argv[])
{
int a, b, count, answer;
char op;
// print the prompt
printf("Enter an expression; ");
// get the expression
count = scanf("%d %c %d", &a, &op, &b);
if (count!=3) {
printf("Bad expression\n");
return 1;
}
// perform the computation
answer = calculate(a, b, op);
// print the answer
printf("%d %c %d = %d\n", a, op, b, answer);
return 0;
}
|
__________________
Like what i said? Hit the Thanks Button!
1.83GHz MacBook 160GB HDD 1GB RAM
3.06GHz iMac 320GB HDD 2GB RAM
SEARCH BEFORE POSTING
|
03-24-2008, 01:57 PM
|
iPhoneaholic
|
|
Join Date: Oct 2007
Posts: 329
Thanks: 28
Thanked 97 Times in 62 Posts
|
|
wow that's great news ! I'm actually happy for you lol
here's to more complex apps in the future..
|
__________________
If I help you out, help me out by clicking the button
|
03-24-2008, 02:25 PM
|
|
Livin the iPhone Life
|
|
|
|
Quote:
Originally Posted by TheHK
wow that's great news ! I'm actually happy for you lol
here's to more complex apps in the future..
|
Yeah, im hoping to make iPhone apps xD
|
__________________
Like what i said? Hit the Thanks Button!
1.83GHz MacBook 160GB HDD 1GB RAM
3.06GHz iMac 320GB HDD 2GB RAM
SEARCH BEFORE POSTING
|
03-24-2008, 10:27 PM
|
|
I see you are using C++ instead of Obj-C. I know C++ really well, but I want to start learning Obj-C...
|
|
03-25-2008, 03:49 AM
|
|
My iPhone is a Part of Me
|
|
|
|
__________________
"Its better to be a pirate than join the navy"Steve Jobs
Iphone-1.1.3-04.03.13g-everything working-telstra
|
03-25-2008, 07:23 PM
|
|
Livin the iPhone Life
|
|
|
|
Quote:
Originally Posted by Kev1000000
I see you are using C++ instead of Obj-C. I know C++ really well, but I want to start learning Obj-C...
|
Yeah i want to to, but it doesn't seem like a good starting point for some reason for a first time developer, i want to learn C then Objective C, just need to learn about OOP.
|
__________________
Like what i said? Hit the Thanks Button!
1.83GHz MacBook 160GB HDD 1GB RAM
3.06GHz iMac 320GB HDD 2GB RAM
SEARCH BEFORE POSTING
|
03-26-2008, 04:55 PM
|
My iPhone is a Part of Me
|
|
|
|
::bows down:: nice your on the path i sure would like to fallow. im stucking waiting till i grad. form HS, and get a pretty macbook pro
|
|
03-26-2008, 05:08 PM
|
|
Developer
|
|
|
|
1. You can compile this with the Windows toolchain and run it on a jailbroken phone.
2. You don't need to restart, you want to do what is called a Read-Eval-Print loop, which means you need an exit command (or let an error do exit) and put the scan in a loop:
while (1) {
puts("Enter an expression: ");
count = scanf("%d %c %d", &a, &op, &b);
if (count != 3) {
puts("Bad expression\n");
return 1;
}
answer = calculate(a, b, op);
printf("%d %c %d = %d\n", a, op, b, answer);
}
(Personal preference - don't comment the obvious.)
|
|
The Following User Says Thank You to NetMage For This Useful Post:
|
|
03-26-2008, 06:05 PM
|
|
iPhone? More like MyPhone
|
|
|
|
dang that looks confusing, good work though, your making progress!
|
__________________
Please don't stop the music
|
The Following User Says Thank You to screamo For This Useful Post:
|
|
03-26-2008, 07:59 PM
|
|
Livin the iPhone Life
|
|
|
|
Quote:
Originally Posted by NetMage
1. You can compile this with the Windows toolchain and run it on a jailbroken phone.
2. You don't need to restart, you want to do what is called a Read-Eval-Print loop, which means you need an exit command (or let an error do exit) and put the scan in a loop:
while (1) {
puts("Enter an expression: ");
count = scanf("%d %c %d", &a, &op, &b);
if (count != 3) {
puts("Bad expressionn");
return 1;
}
answer = calculate(a, b, op);
printf("%d %c %d = %dn", a, op, b, answer);
}
(Personal preference - don't comment the obvious.)
|
Thanks!
|
__________________
Like what i said? Hit the Thanks Button!
1.83GHz MacBook 160GB HDD 1GB RAM
3.06GHz iMac 320GB HDD 2GB RAM
SEARCH BEFORE POSTING
|
The Following User Says Thank You to DoerrFan For This Useful Post:
|
|
|
Thread Tools |
|
Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
Copyright © 2007-08 by ModMy, LLC. All rights reserved. You may not copy anything on this site unless you link to the original.
All times are GMT -6. The time now is 12:41 PM.
Powered by vBulletin® Version 3.6.10 Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 RC5
ModMyiFone.com is an independent
publication and has not been authorized, sponsored, or otherwise approved by Apple, Inc or Cisco Systems, Inc. The information contained on this site is for educational purposes only.
Forum skin by poetic_folly
| |
|
|