George  Koelpin

George Koelpin

1597866960

Using C Dynamic Libraries In Go Programs

My son and I were having fun last weekend building a console based game in Go. I was recreating a game from my youth, back when I was programming on a Kaypro II.

kayproii

I loved this computer. I would write games in BASIC on it all day and night. Did I mention it was portable. The keyboard would strap in and you could carry it around. LOL.

But I digress, back to my Go program. I figured out a way to use the VT100 escape character codes to draw out a simple screen and started programming some of the logic.

Then something horrible happened and I had a major flashback. I could not get input from stdin without hitting the enter key. Ahhhhh I spent all weekend reading up on how to make this happen. I even found two Go libraries that had support for this but they didn’t work. I realized that if I was going to make this happen I needed to build the functionality in C and link that to my Go program.

After a 4 hour coding session at the local Irish pub, I figured it out. I would like to thank Guinness for the inspiration and encouragement I needed. Understand that for the past 10 years I have been writing windows services in C#. For 10 years before that I was writing C/C++ but on the Microsoft stack. Everything I was reading: gcc, gco, static and shared libraries on the Mac and Linux, etc, was foreign to me. I had a lot to learn and still do.

After all my research it became clear I needed to use the ncurses dynamic library. I decided to write a simple program in C using the library. If I could make it work in a compiled C program, I was sure I could get it to work in Go.

Screen Shot

The ncurses library on the Mac is located in /usr/lib. Here is a link to the documentation:

https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man3/ncurses.3x.html

Here is the C header file code for the test program:

test.h

int GetCharacter();
void InitKeyboard();
void CloseKeyboard();

And now the code for the C source file:

test.c

#include <curses.h>
#include <stdio.h>
#include "test.h"

int main() {
  InitKeyboard();

  printf("\nEnter: ");
  refresh();

  for (;;) {
    int r = GetCharacter();
    printf("%c", r);
    refresh();

    if (r == ‘q’) {
      break;
    }
  }

  CloseKeyboard();

  return 0;
}

void InitKeyboard() {
  initscr();
  noecho();
  cbreak();
  keypad(stdscr, TRUE);
  refresh();
}

int GetCharacter() {
  return getch();
}

void CloseKeyboard() {
  endwin();
}

Now the hard part. How do I build this program using the gcc compiler? I want to make sure I am using the same compiler that Go is using. I also want to make sure I am using the bare minimum parameters and flags.

After about an hour of researching, I came up with this makefile. I told you, I have never done this before.

#go

What is GEEK

Buddha Community

Using C Dynamic Libraries In Go Programs
Abdullah  Kozey

Abdullah Kozey

1617695702

Learning C: Input and Output and Two Program Templates

Before I get too deep into C, I need to show you how to get data into and out of your programs. Using assignment for data gets old after a while and you want to be able to have users enter their own data. And you definitely need to be able to see what happens to your data in a program so learning how to display data to the screen is important and necessary.

Besides demonstrating how to perform input and output in C, I will also be demonstrating two templates that are related to those topics — Prompt, Then Read and Input, Process, Output (IPO). The IPO template, in particular, is important because practically every C program you write will use this template.

When I talk about input and output in C, I’ll use the terms standard input and standard output. These terms refer to the default input and output devices on your computer. The standard input device is the keyboard. The standard output device is the computer’s monitor or screen. I will only use the terms input and output and when I use those terms I’m referring to standard input and standard output. If I want to refer to a different device for input and/or output, I’ll use the specific term for that device.

#c-programming-language #c-programming #c-program #c-programming-help

Ari  Bogisich

Ari Bogisich

1589821800

WASI Development Toolchain for C/C++

We realized that compiling already existing C/C++ projects to WASI was much more challenging than we expected. This is because of two main reasons:

  1. It’s not trivial to install and use the WASI SDK
  2. It’s quite hard to port existing projects to WASI as it requires a tighter integration with all configuration and make tools

Inspired by these challenges we have been working non-stop on improving the tooling so it’s easier for anyone to use and adopt WebAssembly and WASI!

#programming #c-programming #c #c# #c++

Anil  Sakhiya

Anil Sakhiya

1607339640

C programming for Beginners | Learn C Programming | C Language

C Language is an evergreen language and is used widely across different industries, This C programming is a must for students and working professionals to become a great Software Engineer especially when they are working in Software Development Domain. Great Learning brings you this live session on “Introduction to C”. In this live session, we will be covering major concepts in C Programming such as Different Variables, Different Data Types that are being used, its Operators, Flow control statements, Structure, and lot more.

#c #programming #developer #c-programming #c-language

Pass method as parameter using C# | Delegates in C# | C# Bangla Tutorial | Advanced C#

https://youtu.be/GfcTSJf5Rc8

#oop in c# #object oriented programming in c# #object oriented concept in c# #learn oop concept #advance c# #pass method as parameter using c#

Ari  Bogisich

Ari Bogisich

1589816580

Using isdigit() in C/C++

In this article, we’ll take a look at using the isdigit() function in C/C++. This is a very simple way to check if any value is a digit or not. Let’s look at how to use this function, using some simple examples.

#c programming #c++ #c #c#