Skip to content

Commit

Permalink
Updated README
Browse files Browse the repository at this point in the history
  • Loading branch information
elliotchance committed Mar 18, 2017
1 parent b8c1839 commit f0103b8
Showing 1 changed file with 51 additions and 3 deletions.
54 changes: 51 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,42 @@ the hard work.

# How?

```bash
python c2go.py tests/hello-world.c
Let's use
[prime.c](https://github.com/elliotchance/c2go/blob/master/tests/prime.c):

```c
#include <stdio.h>

int main()
{
int n, c;

printf("Enter a number\n");
scanf("%d", &n);

if ( n == 2 )
printf("Prime number.\n");
else
{
for ( c = 2 ; c <= n - 1 ; c++ )
{
if ( n % c == 0 )
break;
}
if ( c != n )
printf("Not prime.\n");
else
printf("Prime number.\n");
}
return 0;
}
```

```bash
python c2go.py tests/prime.c
```

```go
package main

import (
Expand All @@ -22,7 +53,24 @@ import (
// ... lots of system types in Go removed for brevity.

func main() {
fmt.Printf("Hello World\n")
var n int
var c int
fmt.Printf("Enter a number\n")
fmt.Scanf("%d", &n)
if n == 2 {
fmt.Printf("Prime number.\n")
} else {
for c = 2; c <= n - 1; c += 1 {
if n % c == 0 {
break
}
}
if c != n {
fmt.Printf("Not prime.\n")
} else {
fmt.Printf("Prime number.\n")
}
}
return
}
```
Expand Down

0 comments on commit f0103b8

Please sign in to comment.