Skip to content

Instantly share code, notes, and snippets.

/*
* Exercise 3-5. Write the function itob(n,s,b) that converts the integer n
* into a base b character representation in the string s. In particular,
* itob(n,s,16) formats s as a hexadecimal integer in s.
*/
#include <stdlib.h>
#include <stdio.h>
#include <limits.h>
/*
* Exercise 3-6. Write a version of itoa that accepts three arguments instead
* of two. The third argument is a minimum field width; the converted number
* must be padded with blanks on the left if necessary to make it wide enough.
*/
#include <stdio.h>
#include <limits.h>
#define abs(x) ((x) > 0) ? (x) : -(x)
void itoa(int n, char s[], int width);
@shaobin0604
shaobin0604 / tcpl_ex-3-1.c
Created November 12, 2009 06:19
tcpl_ex-3-1.c
/*
* Exercise 3-1. Our binary search makes two tests inside the loop, when one
* would suffice (at the price of more tests outside.) Write a version with
* only one test inside the loop and measure the difference in run-time.
*/
#include <stdio.h>
#include <time.h>
#define MAX_ELEMENT 20000
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:id="@+id/counter"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Count: 0" />
<LinearLayout android:orientation="horizontal"
package cn.yo2.aquarium.android.testtimer;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
@shaobin0604
shaobin0604 / gist:233733
Created November 13, 2009 10:21
Android GPS Setting
// check if gps is enabled
locationManager.isProviderEnabled("gps");
// jump to gps setting
startActivity(new Intent("android.settings.LOCATION_SOURCE_SETTINGS"));
mParameters.remove("gps-latitude");
mParameters.remove("gps-longitude");
mParameters.remove("gps-altitude");
mParameters.remove("gps-timestamp");
mParameters.set("jpeg-quality", 85);
mParameters.set("gps-latitude", String.valueOf(25.050357818603516));
mParameters.set("gps-longitude", String.valueOf(102.70413208007813));
mParameters.set("gps-altitude", String.valueOf(1800.0));
mParameters.set("gps-timestamp", String.valueOf(
mParameters.removeGpsData();
mParameters.setJpegQuality(85);
mParameters.setGpsLongitude(longitude);
mParameters.setGpsLatitude(latitude);
mParameters.setGpsAltitude(altitude);
mParameters.setGpsTimestamp(timestamp);
camera.setParameters(mParameters);
camera.takePicture(null, null, jpegPictureCallback);
/*
* Exercise 4-1. Write the function strindex(s,t) which returns the position
* of the rightmost occurrence of t in s, or -1 if there is none.
*/
#include <stdio.h>
#include <string.h>
int strindex(char s[], char t[]);
int main(void)
/*
* Exercise 4-2. Extend atof to handle scientific notation of the form
* 123.45e-6 where a floating-point number may be followed by e or E and an
* optionally signed exponent.
*/
#include <stdio.h>
#include <ctype.h>
#define EPSILON 0.000001