Na linguagem C não existe o tipo de dados "String" como em Java existe por exemplo. Na linguagem C uma string na verdade é um VETOR de CARACTERES representado pelo tipo char e com um tamanho definido pelo programador, por exemplo:
char texto[100];
Nesse caso acima essa "string" pode receber até 100 caracteres. A primeira posição desse vetor de caracteres(string) será texto[0] (Variável texto na posição 0 que será a primeira posição). Na última posição da string o caracter nulo será armazenado que é representado por '\0'. Vamos supor que o usuário tenha digitado na o nome ALEX armazenado na variável texto. Veja como ficaria:
texto[0] = 'A';
texto[1] = 'L';
texto[2] = 'E';
texto[3] = 'X';
texto[4] = '\0';
Vamos ver um código demonstrando a ocorrência de um caracter em uma string
terça-feira, 21 de outubro de 2008
sexta-feira, 17 de outubro de 2008
C language - Adding 2 numbers
Hey :)
What is a variable ?
let's suppose you want to add 2 numbers, each number, each value needs a space in the memory, you need to store this 2 numbers in "variables", because of that, you need to declare at the beginning of your program.
let's look at our code:
# include < stdio.h >
# include < stdlib.h >
int main()
{
int num1, num2, result; //Let's declare 3 variables
printf("Type the first number "); //Write this message
scanf("%d", &num1); //Read the value, "%d" means is a integer
printf("Type the first number "); //Write this message
scanf("%d", &num2); //Read the value, "%d" means is a integer
result = num1 + num2; //Result = num1 plus num2
printf("%d + %d eh %d", num1, num2, result); //Write the value of these variables
printf("\n\n");
system("pause");
}
What is a variable ?
let's suppose you want to add 2 numbers, each number, each value needs a space in the memory, you need to store this 2 numbers in "variables", because of that, you need to declare at the beginning of your program.
let's look at our code:
# include < stdio.h >
# include < stdlib.h >
int main()
{
int num1, num2, result; //Let's declare 3 variables
printf("Type the first number "); //Write this message
scanf("%d", &num1); //Read the value, "%d" means is a integer
printf("Type the first number "); //Write this message
scanf("%d", &num2); //Read the value, "%d" means is a integer
result = num1 + num2; //Result = num1 plus num2
printf("%d + %d eh %d", num1, num2, result); //Write the value of these variables
printf("\n\n");
system("pause");
}
terça-feira, 14 de outubro de 2008
C Language - Hello World
Today is our first program written by Alex Jilas :) and please take a look.
#include < stdio.h> //It's necessary to include this header to use "printf" instruction
#include < stdlib.h> //We're using this header because of system("pause") instruction
int main() //Main function (we're going to talk about later)
{
printf("Hello World :) "); //write "Hello world" in the screen
system("pause"); //Wait for something
}
If you don't use the system("pause") function you're not going to see the phrase you wrote before, in this case "Hello World", compile this code and then compile it again without the system("pause") and notice the difference.
That's all for today!!!
#include < stdio.h> //It's necessary to include this header to use "printf" instruction
#include < stdlib.h> //We're using this header because of system("pause") instruction
int main() //Main function (we're going to talk about later)
{
printf("Hello World :) "); //write "Hello world" in the screen
system("pause"); //Wait for something
}
If you don't use the system("pause") function you're not going to see the phrase you wrote before, in this case "Hello World", compile this code and then compile it again without the system("pause") and notice the difference.
That's all for today!!!
sábado, 11 de outubro de 2008
English Learning
Today is the first post of the blog, I hope you enjoy it.
I've been thinking about why brazilians speak english so slowly and don't speak as well as native speakers, of course native speakers have been speaking english since they were children but there's another thing, brazilians usually say: "I'd like to study there, School X is the best", how do you say that about a school if you don't know it ?
Actually I don't have any problems with english schools :)
Most students study one or two hours a week in a english school, and when they get home they don't study anything, sometimes we need to re-think our concepts, Who has been making mistakes ?
Students or English schools ?
I don't know the exactly answer but I think if you really want to learn something you need to study english the correct way, most schools ignore it, you need to learn REAL ENGLISH.
I'll stop it today but before I'll show you some expressions used by native speakers.
Please take a look:
gimme - Give me
Example: gimme the butter please (Me dê a manteiga por favor)
that's dope - excellent, great (slang)
Example: That's dope! I'll get some e-mails today
gotcha - I got you
Example: gotcha, don't try to lie, I found out everything (te peguei, não tente mentir eu descobri tudo)
Whaddup - what's up (informal way to greet)
Example: hey whatddup alex ? (E ae Alex ? Que que tá rolando ?)
lemme - let me
example: lemme try to help you, I got some medicines here (Me deixe ajudá-lo, tenho alguns remédios aqui)
buddies - guys, friends
example: hey, our buddies are you over there, they just got home (Nossos camaradas estão logo ali, eles acabaram de chegar em casa)
This is enough for today.
I've been thinking about why brazilians speak english so slowly and don't speak as well as native speakers, of course native speakers have been speaking english since they were children but there's another thing, brazilians usually say: "I'd like to study there, School X is the best", how do you say that about a school if you don't know it ?
Actually I don't have any problems with english schools :)
Most students study one or two hours a week in a english school, and when they get home they don't study anything, sometimes we need to re-think our concepts, Who has been making mistakes ?
Students or English schools ?
I don't know the exactly answer but I think if you really want to learn something you need to study english the correct way, most schools ignore it, you need to learn REAL ENGLISH.
I'll stop it today but before I'll show you some expressions used by native speakers.
Please take a look:
gimme - Give me
Example: gimme the butter please (Me dê a manteiga por favor)
that's dope - excellent, great (slang)
Example: That's dope! I'll get some e-mails today
gotcha - I got you
Example: gotcha, don't try to lie, I found out everything (te peguei, não tente mentir eu descobri tudo)
Whaddup - what's up (informal way to greet)
Example: hey whatddup alex ? (E ae Alex ? Que que tá rolando ?)
lemme - let me
example: lemme try to help you, I got some medicines here (Me deixe ajudá-lo, tenho alguns remédios aqui)
buddies - guys, friends
example: hey, our buddies are you over there, they just got home (Nossos camaradas estão logo ali, eles acabaram de chegar em casa)
This is enough for today.
Assinar:
Postagens (Atom)