Ir para conteúdo
Fórum Script Brasil

Mateus GP

Membros
  • Total de itens

    16
  • Registro em

  • Última visita

Tudo que Mateus GP postou

  1. #include <stdio.h> typedef struct{ int num; } reg1; typedef struct { reg1 numero; } reg2; void calcula(reg2* reg); int main () { reg2 reg; calcula(&reg); printf ("%d", reg.numero.num); return 0; } void calcula (reg2* reg){ reg->numero.num = 5; }
  2. #include <stdio.h> typedef unsigned char String; void stringAddAll(String *s, char *a /* equivalente a a[]*/, int n) { while(*s != 0) s++; while(n--) *s++ = *a++; *s = 0; } int main(int argc, char **argv) { String str[256] = "hello"; char a[] = " world!"; stringAddAll(str, a, 7); puts((char*)str); return 0; }
  3. Mateus GP

    AJUDA

    Maa, o que você realmente deseja saber? Especifique sua dúvida, como não a esclareceu fiz um código, que creio ser o que você quer. #include <stdio.h> int main(int argc, char **argv) { int num; puts("INTRODUZA UM NUMERO"); scanf("%d%*c", &num); if(num == 0) puts("O NUMERO É NULO"); else if(num < 0) puts("É UM NUMERO NEGATIVO"); else puts("É UM NUMERO POSITIVO"); return 0; }
  4. Dennis Ritchie - Linguagem C "The C Programming Language", Dennis Ritchie, Brian Kernighan, (1978) (No Brasil: C - A Linguagem de Programação - Ed. Campus, 1986) James Gosling - Linguagem Java Ken Arnold, James Gosling, David Holmes, The Java Programming Language, Fourth Edition, Addison-Wesley Professional, 2005, ISBN 0321349806 James Gosling, Frank Yellin, The Java Team, The Java Application Programming Interface, Volume 2: Window Toolkit and Applets, Addison-Wesley, 1996, ISBN 0201634597 James Gosling, Frank Yellin, The Java Team, The Java Application Programming Interface, Volume 1: Core Packages, Addison-Wesley, 1996, ISBN 0201634538 Yukihiro Matsumoto - Linguagem Ruby Ruby in a Nutshell ISBN 0-596-00214-9 The Ruby Programming Language ISBN 0-596-51617-7 Bjarne Stroustrup - Linguagem C++ Bjarne Stroustrup. The C++ Programming Language. 3 ed. [s.l.]: Addison-Wesley, 2000. ISBN 0-201-70073-5 Bjarne Stroustrup. The Design and Evolution of C++. 1 ed. [s.l.]: Addison-Wesley, 1994. ISBN 0-201-54330-3 Margaret A. Ellis e Bjarne Stroustrup. The Annotated C++ Reference Manual. [s.l.]: Addison-Wesley, 1990. ISBN 0-201-51459-1 Andrei Alexandrescu, Andrew Koenig, Stanley B. Lippman, Bjarne Stroustrup, Herb Sutter e Barbara E. Moo. C++ In-Depth Box Set. [s.l.]: Addison-Wesley, 2002. 1568 p. ISBN 0201775816 John McCarthy - Linguagem Lisp McCarthy, J. 1959. Programs with Common Sense. In Proceedings of the Teddington Conference on the Mechanization of Thought Processes, 756-91. London: Her Majesty's Stationery Office. McCarthy, J. 1960. Recursive functions of symbolic expressions and their computation by machine. Communications of the ACM 3(4):184-195. McCarthy, J. 1963a A basis for a mathematical theory of computation. In Computer Programming and formal systems. North-Holland. McCarthy, J. 1963b. Situations, actions, and causal laws. Technical report, Stanford University. McCarthy, J., and Hayes, P. J. 1969. Some philosophical problems from the standpoint of artificial intelligence. In Meltzer, B., and Michie, D., eds., Machine Intelligence 4. Edinburgh: Edinburgh University Press. 463-502. McCarthy, J. 1977. Epistemological problems of artificial intelligence. In IJCAI, 1038-1044. McCarthy, J. 1980. Circumscription: A form of non-monotonic reasoning. Artificial Intelligence 13(1-2):23-79. McCarthy, J. 1986. Applications of circumscription to common sense reasoning. Artificial Intelligence 28(1):89-116. McCarthy, J. 1990. Generality in artificial intelligence. In Lifschitz, V., ed., Formalizing Common Sense. Ablex. 226-236. McCarthy, J. 1993. Notes on formalizing context. In IJCAI, 555-562. McCarthy, J., and Buvac, S. 1997. Formalizing context: Expanded notes. In Aliseda, A.; van Glabbeek, R.; and Westerstahl, D., eds., Computing Natural Language. Stanford University. Also available as Stanford Technical Note STAN-CS-TN-94-13. McCarthy, J. 1998. Elaboration tolerance. In Working Papers of the Fourth International Symposium on Logical formalizations of Commonsense Reasoning, Commonsense-1998. Costello, T., and McCarthy, J. 1999. Useful counterfactuals. Electronic Transactions on Artificial Intelligence 3(A):51-76 McCarthy, J. 2002. Actions and other events in situation calculus. In Fensel, D.; Giunchiglia, F.; McGuinness, D.; and Williams, M., eds., Proceedings of KR-2002, 615-628.
  5. Fiz um código para demonstrar uma possível solução para o problema apresentado, mas por tê-lo feito rapidamente, sem dedicar muito esforço pode haver falhas e/ou erros, por isso modifique-o para suas necessidades. /* * main.c * * Copyright 2012 Mateus G. Pereira <mateusgpe@hotmail.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301, USA. * * */ #include <string.h> #include <stdlib.h> #include <stdio.h> #include <ctype.h> typedef struct Aluno { int Cod; char nome[30]; float n1; float n2; float n3; } Aluno; int scmp (const char* s1, const char* s2) { while(isspace(*s1)) s1++; while(*s2 != '') if(toupper(*s1++) != toupper(*s2++)) return 0; return 1; } int stok (char* d, char t, char* s) { static char* str = NULL; if(s != NULL) str = s; else if(str == NULL) return 0; while(*str == t) str++; while((*str != t) && (*str != '')) *d++ = *str++; *d = ''; return *str++ != ''; } int structset (Aluno* al, char* s) { char label[128], value[192]; char* str; if(stok(label, ':', s) == 0) return 0; stok(value, '\n', NULL); str = value; while(isspace(*str)) str++; if(scmp(label, "ALUNO")) strncpy(al->nome, str, 30); else if(scmp(label, "COD")) al->Cod = (int) strtol(str, NULL, 10); else if(scmp(label, "NOTA1")) al->n1 = (int) strtod(str, NULL); else if(scmp(label, "NOTA2")) al->n2 = (int) strtod(str, NULL); else if(scmp(label, "NOTA3")) al->n3 = (int) strtod(str, NULL); else return 0; return 1; } int main(int argc, char **argv) { int i = 0, p = 0, z = 0; char line[256]; Aluno als[256]; FILE* in; in = fopen(*(argv + 1), "r"); if(in == NULL) return 1; while(fgets(line, 256, in) != 0) { structset(als + i, line); if(p++ >= 4) { p = 0; i++; } if(i >= 256) break; } fclose(in); while(z < i) { printf("[1] %s\n[2] %d\n", als[z].nome, als[z].Cod); printf("[3] %f\n[4] %f\n", als[z].n1, als[z].n2); printf("[5] %f\n\n", als[z].n3); z++; } return 0; }[/CODEBOX]
  6. Eu fiz um codigo para ordernar numeros para um software que desenvolvo, ainda na versão alfa, mais creio que vai ser util. Para melhorar a sua compreenção fiz uma pequena demonstração de como usa-la: #include <stdio.h> #include <stdlib.h> void sort(int* n, size_t num) { size_t p1 = 0, p2; while(p1 < (num - 1)) { p2 = p1 + 1; while(p2 < num) { if(n[p2] > n[p1]) { int tmp; tmp = n[p2]; n[p2] = n[p1]; n[p1] = tmp; } p2++; } p1++; } } int main() { int num[4]; num[0] = 100; num[1] = 1000; num[2] = 150; num[3] = 10; sort(num, 4); fprintf(stdout, "001: %d\n", num[0]); fprintf(stdout, "002: %d\n", num[1]); fprintf(stdout, "003: %d\n", num[2]); fprintf(stdout, "004: %d\n", num[3]); return 0; }
  7. Falar que C não é multiplataforma é engano, pois é uma linguagem POSIX, Java é facil de ser programado, porém é pouco eficiente, um programa em C é notavelmente mais veloz na execução. Java é uma linguagem pré compilada, ou seja, necessita de um interpretador no sistema alvo, já programas em C executam sem qualquer requisitos além do sistema operacional. Isso mostra o motivo do programa que você esta usando e o seu prorprio sistema operacional, provavemente ser escrito em C. Como o Windows e o Linux.
  8. Mateus GP

    Ajuda!

    Veja este codigo (já está em C): Faça algumas alterações pois fiz muito rapido, por isso pode gerar bugs. #include <stdio.h> #include <stdlib.h> #define MAX_NOME 50 #define MAX_FUNCIO 100 typedef struct _FUN { char nome[MAX_NOME]; unsigned int salario; } funcionarios; int leiafuncionarios(funcionarios *fun) { int lidos = 0, n; while(lidos < MAX_FUNCIO) { puts("Insira o nome do funcionario: "); fgets(fun[lidos].nome, MAX_NOME, stdin); if(*fun[lidos].nome == '\n') return lidos; n = strlen((char*)fun[lidos].nome); fun[lidos].nome[n-1] = 0; puts("Insira o salario do funcionario: "); scanf("%u%*c", &fun[lidos].salario); lidos++; } return lidos; } void imprimirfuncionarios(funcionarios* fun, int imprimir) { int tmp = 0; while(tmp < imprimir) { printf("%s, Salario: R$ %u\n", fun[tmp].nome, fun[tmp].salario); tmp++; } } void imprimirfuncionarios5000(funcionarios* fun, int imprimir) { int tmp = 0; while(tmp < imprimir) { if(fun[tmp].salario > 5000) printf("%s, Salario: R$ %u\n", fun[tmp].nome, fun[tmp].salario); tmp++; } } int main(int argc, char* argv[]) { funcionarios fun[MAX_FUNCIO]; int numero = 0; numero = leiafuncionarios(fun); printf("Funcionarios e seus salarios\n"); imprimirfuncionarios(fun, numero); printf("\nFuncionarios com salario maior que 5.000\n"); imprimirfuncionarios5000(fun, numero); return 0; }
  9. Não foi isso, ocorreu um erro no meu navegador, então cliquei uma vez não enviou, duas tambem não (segundo meu navegador)... Depois quando atualizei já estava este monte de dump, mas da para notar que todas foram eviadas praticamente no mesmo momento. Mudando um pouco de foco, sou novo no forum e queria saber se quando ocorre isso há algum modo de desfazer o erro.
  10. Não abandone C, pois ela e Java são as linguagens de programação mais conhecidas, consequentemente mais usadas, neste mês a mais usada é C que ultrapassou Java. Além disso varias linguagens de programação derivam ou tem relações com C, como C++, Objective-C (Usada no Mac OS X e GNUstep)... Fonte: http://www.tiobe.com/index.php/content/pap...tpci/index.html
  11. Mateus GP

    Algoritmo horário.

    Tente esse algoritmo, fiz rapido, por isso teste e faça as modificações que julgar necessarias: #include <stdio.h> typedef unsigned long long int uintm; uintm char2int(const char* adr) { return ((adr[0] - '0')*10)+(adr[1] - '0'); } void int2char(uintm n, char* s) { *s++ = '0' + ((n / 10)%10); *s++ = '0' + (n % 10); *s = 0; } void addsecs2hour(uintm secs, char* hh, char* mm, char* ss) { uintm s, h, m; s = char2int(ss) + secs; m = char2int(mm); h = char2int(hh); s += (m * 60) + (h * 3600); h = s / 3600; m = (s - (h * 3600)) / 60; s -= (h * 3600) + (m * 60); int2char(s, ss); int2char(m, mm); int2char(h, hh); } int main(int argc, char* argv[]) { char h[4], m[4], s[4]; fprintf(stdout, "Insira o horario (hh:mm:ss): "); scanf("%2c%*c%2c%*c%2c%*c", h, m, s); addsecs2hour(1, h, m, s); fprintf(stdout, "Mais um segundo: %s:%s:%s\n", h, m, s); return 0; }
  12. Para tornar o codigo mais legivel e consequentemente menos sucetivel a erros, use mais funções ou macros. O sistema binario é o mais facil em C, veja uma macro getbit: #define getbit(by, pos) ((by >> pos)&0x1) Com ela é possivel criar uma função de conversão, veja: void byte2bits(char c, char* s) { int i = 7; while(i >= 0) *s++ = '0' + getbit(c, i); *s = 0; } O programa final ficaria assim: #include <stdio.h> #define getbit(by, pos) ((by >> pos)&0x1) void byte2bits(char c, char* s) { int i = 7; while(i >= 0) *s++ = '0' + getbit(c, i--); *s = 0; } int main(int argc, char* argv[]) { char bits[9], c; fputs("Inisira um caractere\n", stdout); scanf("%c%*c", &c); byte2bits(c, bits); fprintf(stdout, "No sistema binario %s\n", bits); return 0; }
  13. Sim quebraria, pois uma lista duplamente encadeada não pode ser acessada como um array. Veja um exemplo da estrutura de uma lista encadeada: typedef struct _Lista { int elemento; struct _Lista *prev; struct _Lista *next; } Lista; Como pode ser observado uma lista encadeada é dinamica, ou seja, pode ser adicionar infinitos elementos, diferente de um vetor que possui um tamanho fixo. O acesso a um elemento é feito assim: int getnum(int p, Lista *ls) { Lista *tmp tmp = ls; while(p >= 0) { if(tmp->next != NULL) tmp = tmp->next; p--; } return tmp->elemento; }
  14. Sim quebraria, pois uma lista duplamente encadeada não pode ser acessada como um array. Veja um exemplo da estrutura de uma lista encadeada: typedef struct _Lista { int elemento; struct _Lista *prev; struct _Lista *next; } Lista; [code] Como pode ser observado uma lista encadeada é dinamica, ou seja, pode ser adicionar infinitos elementos, diferente de um vetor que possui um tamanho fixo. O acesso a um elemento é feito assim: [code] int getnum(int p, Lista *ls) { Lista *tmp while(p >= 0) {
  15. Sim quebraria, pois uma lista duplamente encadeada não pode ser acessada como um array. Veja um exemplo da estrutura de uma lista encadeada: typedef struct _Lista { int elemento; struct _Lista *prev; struct _Lista *next; } Lista; [code] Como pode ser observado uma lista encadeada é dinamica, ou seja, pode ser adicionar infinitos elementos, diferente de um vetor que possui um tamanho fixo. O acesso a um elemento é feito assim: [code] int getnum(int p, Lista *ls) { Lista *tmp while(p >= 0) {
  16. Analise este codigo: #include <stdio.h> #include <string.h> int isvogal(int c) { if((c >= 'A')&&(c <= 'Z')) c = 'a' + (c - 'A'); switch(c) { case 'a': case 'e': case 'i': case 'o': case 'u': return 1; } return 0; } int main(int argc, char* argv[]) { char frase[256]; int i = 0; printf("Insira uma frase:\n"); fgets(frase, 256, stdin); while(frase[i] != 0) { if(isvogal(frase[i])) frase[i] = '*'; i++; } printf("Frase: %s\n", frase); return 0; } Espero ter ajudado. Boa Sorte!
×
×
  • Criar Novo...