Giter Site home page Giter Site logo

afp2324_projeto_template's Introduction

AFP2324 Project Template

This is a C program template tailored for:

  • GCC, GDB, MAKE (via MinGW)
  • VS Code IDE

Makefile

Modules should be added to the makefile before compilation.

Compilation

In a terminal, type:

.\make.bat <directive>

where <directive> is optional and can be replaced by:

  • (empty) - compiles the program normally;
  • debug - compile with debug symbols. Necessary to debug the program;
  • clean - removes the compiled executable.

Execution

After compiling, in the terminal, type:

.\prog.exe

Enabling Non-Ascii Characters in PowerShell Terminal

If using PowerShell as the terminal, you can issue the following command to enable non-ascii characters for the program output.

[Console]::OutputEncoding = [Text.Encoding]::Utf8

Debugging

Set your breakpoint(s) and click on the Run and Debug tab on VS Code and click on gdb - Debug project (at the top).

This will open a separate terminal window where the program session will execute (for input and output). You can use the debug options inside VS Code.

Input Module

This template project includes the input module. You should use it for user input as it provides a relatively robust mechanism to read mixed data and performs validation.

Below is a sample program which exemplifies the usage of this module:

#include <stdio.h>
#include <stdlib.h>

#include "input.h"

int main() {

	/* simple data formats with validation examples */
	int value = 0;
	do {
		printf("Integer Value? ");
	} while(!readInteger(&value)); /* loops while invalid */
		
	printf("Integer Value = %d \n", value);

	double value2 = 0;
	do {
		printf("Double Value? ");
	} while(!readDouble(&value2)); /* loops while invalid */
		
	printf("Double Value = %lf \n", value2);

	/* Strings are consumed as-is */
	char text[100];
	printf("Text? ");
	readString(text, 100);
	printf("Text = %s \n", text);

	/* Example of the spliting function; use with CSV files later */
	char line[100] = "Bruno Silva;[email protected];;2023/24";

	char** tokens = splitString(line, 4, ";");
	for(int i=0; i<4; i++) {
		printf("Token[%d] = %s \n", i, tokens[i]);
	}

	free(tokens); 

	return 0;
}

and an example user interaction session:

Integer Value? 12d
Integer Value? - 3
Integer Value? -3
Integer Value = -3 
Double Value? 12.4.5
Double Value? -3.14159
Double Value = -3.141590 
Text? This some text and a number 7 
Text = This some text and a number 7 
Token[0] = Bruno Silva 
Token[1] = [email protected] 
Token[2] =  
Token[3] = 2020/21

afp2324_projeto_template's People

Watchers

Carlos Serpa avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.