Sdg

  • June 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Sdg as PDF for free.

More details

  • Words: 3,261
  • Pages: 9
camping29Jul 13 2008, 09:06 AM Ch�o m� brother c?a C?a s? tin h?c , m�nh m?i l�m quen v?i ng�n ng? C co b?n (m?y d�n anh g?i l� ng�n ng? l?p tr�nh ki?u c?u tr�c ), xem s�ch d?n ph?n string, con tr? , t? vi?t v�i v� d? nh? tr�n n?n DEV-C++, nhung g?p m� l?i kh� h?u qu�, l�n d�y nh? gi?ng h? : 1-B�i con tr?, ko b�t sao m� no ko d?ng l?i cho m�nh xem, m?c d� c� l?n getch(), v?i gi?i th�ch th�m d�m m�nh v? h�m malloc, alloc, khi n�o d�ng ,khi n�o ko, d�ng th� sao, ko th� sao ? CODE#include <stdio.h> #include #include <stdlib.h> main() { int *ptr; int var[]={1,2,3,4,5,6}; //ptr=(int *)malloc(6*sizeof(int)); ptr=var; for(int i=0;i<6;i++) printf("%5s",*(ptr+i)); free(ptr); getch(); } 2- B�i v? String, ch?ng hi?u l� l?i ji, m?c d� tr�n v?n d? ti?ng anh th� m�nh h?u r� n� n�i ji, b� tay th?t CODE#include <stdio.h> #include #include <string.h> main() { char word[10],string[10]; int n=0; printf("\nEnter a word(no space character) : "); scanf("%s",word); printf("\nThe word is : %s",word); printf("\nEnter a string(with space character) : "); do { scanf("%s",string[n]); }while(strcmp(string[n++],'.')); printf("\nThe string is : "); for(int i=0;i
*Th�i so so ? d�y 2 b�i d�, c� ji m�nh h?i sau nha, thx m?y bro nh�u. Yahoo m�nh : camping29, c� ji c?n trao d?i th� PM nha. Thanks again hoang_daoduyJul 13 2008, 03:17 PM Ch�i v?i b�i 1, b?n c?n ph?i c?p ph�t b? nh? cho con tr? ch? b?n d�nh d?u c�i l?nh malloc v�o th� n? b�o l?i ? l?nh g�n l� d�ng r?i, c�n n?u mu?n s? d?ng l?nh malloc m� b?n kh�ng khai b�o thu vi?n th� sao ch?y du?c #include B�i 2 : scanf("%s",word); --------> scanf("%s",&word); ho?c c� th? s? d?ng gets(word); do { scanf("%s",string[n]); ----------> scanf("%c", &string[n]); }while(strcmp(string[n++],'.')); N?u b?n d? th? n�y th� n� s? nh?n chu?i input l� x�u ch? kh�ng pha? l� k� t? nhu v?y ch?c ch?n 100% sai for(int i=0;i>>>>>>>>>>> printf("%c\t",string[i]); Have Fun camping29Jul 13 2008, 10:57 PM QUOTE Ch�i v?i b�i 1, b?n c?n ph?i c?p ph�t b? nh? cho con tr? ch? b?n d�nh d?u c�i l?nh malloc v�o th� n? b�o l?i ? l?nh g�n l� d�ng r?i, c�n n?u mu?n s? d?ng l?nh malloc m� b?n kh�ng khai b�o thu vi?n th� sao ch?y du?c #include

-H�nh nhu b?n ch? gi?i b�i 1 tr�n l� thuy?t ph�i ko? B�i 1 m�nh d? h�m malloc trong d?u "//" th� c� nghia l� m�nh d� th? 2 tru?ng h?p c� malloc v� ko c� malloc r?i ( t?i m?i t�m hi?u n�n ph?i dua ra c�c tru?ng h?p d? th?.) - C�n v? vi?c ch?y th� m�nh d� n�i ? tr�n: QUOTE ko b�t sao m� no ko d?ng l?i cho m�nh xem, m?c d� c� l?n getch() T?c l� d� ch?y dc nhung m� ngay sau khi ch?y th� n� close lun, ko d?ng l?i ? m�n h�nh CMD d? m�nh xem. -Theo m�nh bi?t th� thu vi?n stdlib.h d� ch?a d?y d? c�c h�m malloc, alloc, realloc, v� n�i th�m l� gi�o tr�nh m�nh dang theo d�i l� gi�o tr�nh softtechaptech n�n kh� tin c?y, m?c d� v?n c� v?n c� v�i l?i nh? ko d�ng k?. *B�i 2 : QUOTE scanf("%s",word); --------> scanf("%s",&word);

-B?n c� th? gi?i th�ch th�m gi�p m�nh ? ch? k� t? & ko, theo m�nh hi?u th� format code %s th� khi b�o ph?n agrument th� ko c� d?u &, c� th? � b?n l� scan gi� tr? v�o d?a ch? c?a word, nhung v? m?t c?u tr�c th� m�nh kh�ng h?u l?m, gi?ng th�m h? c�i. QUOTE do { scanf("%s",string[n]); ----------> scanf("%c", &string[n]); }while(strcmp(string[n++],'.')); N?u b?n d? th? n�y th� n� s? nh?n chu?i input l� x�u ch? kh�ng pha? l� k� t? nhu v?y ch?c ch?n 100% sai -T?i sao l� sai, n� nh?n chu?i input l� x�u th� cu?i b�i m�nh print ra cung l� ki?u x�u. -Theo m�nh bi?t th� format code %c xem a space( k� t? tr?ng ) l� 1 k� t?.V?y th� format code %s th� sao, v� n?u m�nh khai b�o l� %s m� nh?p v�o k� t? tr?ng th� c� g� x?y ra.VD : CODEprintf("Nhap xau:"); scanf("%s",str); N?u Input l�: Cuaso tinhoc(k?t th�c = ph�m Enter) Th� N� s? nh?n chu?i l� Cuaso hay l� Cuuso tin hoc. * Mong c�c bro tr? l?i gi�p m�nh s?m, thx . hoang_daoduyJul 14 2008, 12:14 AM Srry b?n, m�nh chua ch?y th? m� n�i lu�n t?i nh� kh�ng c� Dev-C. V?i b�i 1 l�c d?u m�nh d?c n�n hi?u nh?m code. Th?c s? l� n� kh�ng c?n c?p ph�t b? nh? cho con tr? v� con tr? n�y d� du?c g�n d?a ch? v�o v? tr� d?u c?a m?ng var. M�nh cung kh�ng hi?u du?c t?i sao l?i Dev-C++ c?a b?n l?i b? th?, c�n m�nh d� test tr�n Borlen-C th?y ok l?m. �ang ? ch? kh�c m� m�y l�m vi?c l?i d? ? nh� n�n kh�ng c� di?u ki?n test.

C�n v? stdlib.h cung c� malloc th� th?c s? ng�y xua m�nh h?c ki?u 1+1=2 n�n kh�ng ch� � l?m, gi?ng vi�n d?y j m�nh l�m theo v?y V?i b�i 2: d?i v?i l?nh scanf -> khi n�o c?n & v� khi n�o kh�ng c?n &. Kh�ng c?n & khi bi?n d� l� 1 con tr? d? m� ch?y du?c, nhung sai thu?t to�n CODE do { scanf("%s", &string[n]); }while(strcmp(&string[n++],".")); ch?nh thu?t to�n: CODE do

{ scanf("%c", &string[n]); }while(strcmp(&string[n++],".")); Nhung nghi di nghi l?i th� th?y c�i n�y r?t v� l�, b?i v� sao? b?i v� theo � v�ng while n�y ngu?i s? d?ng mu?n l� nh?p 1 k� t? t? b�n ph�m v� ki?m tra n?u n� l� "." th� s? tho�t, nhung v?i l?nh scanf n� ch? k?t th�c nh?p ch? khi n�o ?n enter. do d� v?i thu?t to�n th? kia l� kh�ng d�ng ? m�nh chua c� d? b�i n�n chua hi?u h?t d?oc... B?n th? dua d? b�i l�n d�y xem sao camping29Jul 14 2008, 10:26 PM VD ? d�y ch? don gi?n l� nh?p 1 t? r?i in t? d� ra, sau d� nh?p 1 chu?i k� t? d?ng c�u, t?c l� c� d?u c�ch, v� in ra c�u d�. QUOTE Nhung nghi di nghi l?i th� th?y c�i n�y r?t v� l�, b?i v� sao? b?i v� theo � v�ng while n�y ngu?i s? d?ng mu?n l� nh?p 1 k� t? t? b�n ph�m v� ki?m tra n?u n� l� "." th� s? tho�t, nhung v?i l?nh scanf n� ch? k?t th�c nh?p ch? khi n�o ?n enter. do d� v?i thu?t to�n th? kia l� kh�ng d�ng ? - C?m on do?n n�y m�nh hi?u r?i, d? m�nh tr�ch nguy�n van trong s�ch ra nha : ( trang 97-gi�o tr�nh Elementary Programming With C(Ti?ng Anh) c?a Aptech Worldwide m�nh photo d?oc t? b?n, ch? th?c s? th� m�nh ko c� d? ti?n d? h?c kh�a n�y ) QUOTE White space character in control string are normally ignored except that it causes problems with %c format code. If we use %c specifier, then a space considered a valid character. -T?m d?ch l�: K� t? tr?ng ? x�u chu?i di?u khi?n dc t? d?ng b? qua tr? khi (except) n� c� v?n d? v?i format code %c. N?u ch�ng ta d�ng %c, th� k� t? tr?ng dc coi nhu k� t? h?p l? . - � m�nh ? d�y d�ng l� nh?p 1 k� t? t? b�n ph�m v� ki?m tra n?u n� l� "." th� s? d?ng( hok f?i tho�t nha ) nhung m�nh d� ki?m tra th� ko c� v?n d? j� v?i vi?c s? d?ng h�m scanf v?i l?p do...while( qua v�i v� d? nh?), h�m scanf v?n d?ng bt. - ? d� f?i s?a l?i l� : CODEdo { scanf( "%c" , &string[n] ); }while(strcmp (string[n++],'.') ); printf("\nThe string is : "); for(int i=0;i
3 - invalid conversion from `char' to `const char*' 4 - initializing argument 2 of `int strcmp(const char*, const char*)' DarkJul 14 2008, 11:53 PM QUOTE(camping29 @ Jul 14 2008, 10:26 PM) VD ? d�y ch? don gi?n l� nh?p 1 t? r?i in t? d� ra, sau d� nh?p 1 chu?i k� t? d?ng c�u, t?c l� c� d?u c�ch, v� in ra c�u d�. QUOTE Nhung nghi di nghi l?i th� th?y c�i n�y r?t v� l�, b?i v� sao? b?i v� theo � v�ng while n�y ngu?i s? d?ng mu?n l� nh?p 1 k� t? t? b�n ph�m v� ki?m tra n?u n� l� "." th� s? tho�t, nhung v?i l?nh scanf n� ch? k?t th�c nh?p ch? khi n�o ?n enter. do d� v?i thu?t to�n th? kia l� kh�ng d�ng ? - C?m on do?n n�y m�nh hi?u r?i, d? m�nh tr�ch nguy�n van trong s�ch ra nha : ( trang 97-gi�o tr�nh Elementary Programming With C(Ti?ng Anh) c?a Aptech Worldwide m�nh photo d?oc t? b?n, ch? th?c s? th� m�nh ko c� d? ti?n d? h?c kh�a n�y ) QUOTE White space character in control string are normally ignored except that it causes problems with %c format code. If we use %c specifier, then a space considered a valid character. -T?m d?ch l�: K� t? tr?ng ? x�u chu?i di?u khi?n dc t? d?ng b? qua tr? khi (except) n� c� v?n d? v?i format code %c. N?u ch�ng ta d�ng %c, th� k� t? tr?ng dc coi nhu k� t? h?p l? . - � m�nh ? d�y d�ng l� nh?p 1 k� t? t? b�n ph�m v� ki?m tra n?u n� l� "." th� s? d?ng( hok f?i tho�t nha ) nhung m�nh d� ki?m tra th� ko c� v?n d? j� v?i vi?c s? d?ng h�m scanf v?i l?p do...while( qua v�i v� d? nh?), h�m scanf v?n d?ng bt. - ? d� f?i s?a l?i l� : CODEdo { scanf( "%c" , &string[n] ); }while(strcmp (string[n++],'.') ); printf("\nThe string is : "); for(int i=0;i
t?t c? d?u b�o ? d�ng "}while(strcmp (string[n++],'.') `char' to `const char*' of `int strcmp(const char*, const char*)' `char' to `const char*' of `int strcmp(const char*, const char*)'

B?n oi h�m strcmp ko nh?n ki?u char m� n� ch? nh?n char* (con tr? ki?u char), b?n v?t ki?u char v�o d� th� n� b�o l?i l� d�ng r?i. Th? 2 l� getch() kh�ng d?ng l� b?i v� b?n d�ng scanf, sau khi scanf k?t th�c n� s? d? l?i 1 k� t? '\n' trong input stream, h�m getch() d?c input stream v� l?y du?c 1

k� t? do d� n� kh�ng d?ng, getch() ch? d?ng khi input stream is empty. M� b?n vi?t C kinh qu�, ki?m cu?n Absolute C++ c?a t�c gi? Walter Savitch d?c di, m?c d� l� C++ nhung sau khi d?c xong b?n s? hi?u r?t nhi?u v?n d? b?n d� v?p ph?i v?i C. B?n kh�ng hi?u getch() v� scanf(). ��ng l? trong v�ng l?p ph?i d�ng getch() b?n l?i d�ng scanf(). Code r?t b?t c?n, sai nhi?u l?m, vi?t l?i di. �?u h�ng v� p� tay Aptech vi?t ki?u n�y th� ch?t th?t, ph?i di check l?i r?i g�p � m?i du?c. DarkJul 15 2008, 12:32 AM Cho b?n 1 l?i khuy�n l� d?ng di l?y s�ch Aptech m� h?c. d� ch? l� s�ch gi�o tr�nh. Ph?i c� ngu?i hu?ng d?n l� 1. C�i n?a l� lu?ng ki?n th?c trong d� ch? l� c�i d?u kim c?a C th�i. B?n mu?n h?c th� s�ch Aptech kh�ng ph?i l� 1 l?a ch?n hay, th?m ch� l� t?i nh?t. B?n d� c� ch� h?c b?ng ti?ng Anh th� hay l�n trang http://gigapedia.org ho?c http://itstudy8.org d? down s�ch v? d?c. B?n th�n tui cung ph?i t? h?c d?n 2 nam m?i r�nh v? C. �� l� l� do t?i sao b�y gi? nhi?u ngu?i d? x� h?c Java v� C#, don gi?n v� C# v� Java ? 1 b?c cao hon trong c?p b?c ng�n ng? v� kh�ng ph?c t?p nhu C. So s�nh C#, Java v?i C/C++ th� qu? th?t l� kh�ng th? du?c b?i v� d� l� 2 th? gi?i kh�c. N?u c� ai b?o C# m?nh hon C++ hay C++ m?nh hon th� d� l� v� kh�ng hi?u C# v� C++ ra sao c?. Ch�c may m?n v� th�nh c�ng. V?n s? kh?i d?u nan, d?ng n?n ch�. hoang_daoduyJul 15 2008, 12:35 AM M�nh th?y hoi kh� hi?u t?i v� b?n b?o l� d� ch?y chuong tr�nh v� th?y n� v?n ho?t d?ng b�nh thu?ng m� l?i c� l?i l� sao CODE"}while(strcmp (string[n++],'.') );" C�n d�ng n�y b?n thay b?ng CODE

"}while(strcmp (&string[n++],".") );"

c�n l� do th� nhu anh Dark n�i d� b?n. + V?n d? v�ng while d� c?a b?n, m�nh tin r?ng n� s? ch?y kh�ng d�ng, d?m b?o. camping29Jul 15 2008, 10:33 PM Theo g�p � th� m�nh n�n d?ng d?c Aptech h?? Aptech m�nh d?c t?i f?n Fuction r?i, j? d?ng, qua C++ d?c h?? Minh m?i h?c nam 1 th�i, th?c t? th� tr�n tr?ong d?y ko bao nhi�u, ch? y?u l� t? d?c, v?y j? c� chuy?n qua C++ hay d?c l?ot qua h?t C ? DarkJul 15 2008, 11:01 PM QUOTE(camping29 @ Jul 15 2008, 10:33 PM) Theo g�p � th� m�nh n�n d?ng d?c Aptech h?? Aptech m�nh d?c t?i f?n Fuction r?i, j? d?ng, qua C++ d?c h?? Minh m?i h?c nam 1 th�i, th?c t? th� tr�n tr?ong d?y ko bao nhi�u, ch? y?u l� t? d?c, v?y j? c� chuy?n qua C++ hay d?c l?ot qua h?t C ? B?n t? h?c th� h�y t�m s�ch t? h?c m� d?c, Aptech l� lo?i s�ch gi�o tr�nh. C�i n?a l� c�i C trong s�ch Aptech cu l?m r?i, n� ko ph?i tr?ng t�m c?a Aptech n�n ko du?c ch� tr?ng c?i thi?n. B�y gi? h?c th?ng C++ d�ng cout cin cho kh?e. Cho b?n 1 trang h?c C++ tr?c tuy?n http://www.functionx.com d�y. Gi?i C++ th� b?n s? th?y Java v� C# d? h?c l?m. C? l�n b?n ?. C++ l� 1 trong nh?ng ?i gian nan c?a th? gi?i l?p tr�nh, b?n c� th? b? qua n� d? di nh?ng ?i nh? nh�ng hon, nhung qua

du?c C++ th� b?n s? t? tin l� ch?ng c� ng�n ng? hi?n d?i n�o l� qu� kh�. hoang_daoduyJul 16 2008, 12:47 AM Theo y� ki�n cu?a mi`nh thi` ba?n cu� n�n ho?c n�t ca�c ph�`n co`n la?i trong sa�ch aptech. Sau do� ba?n chuy�?n qua c++ ho?c th� na`o la` Object + ... No�i chung C chi? la` d�? la`m quen vo�i l�?p tri`nh th�i co`n d�? ho?c ca�i hay ho thi` nhanh nhanh chuy�?n sang C++ Good luck! Lake999Jul 19 2008, 04:17 AM QUOTE (camping29 @ Jul 13 2008, 09:06 AM) Ch�o m� brother c?a C?a s? tin h?c , m�nh m?i l�m quen v?i ng�n ng? C co b?n (m?y d�n anh g?i l� ng�n ng? l?p tr�nh ki?u c?u tr�c ), xem s�ch d?n ph?n string, con tr? , t? vi?t v�i v� d? nh? tr�n n?n DEV-C++, nhung g?p m� l?i kh� h?u qu�, l�n d�y nh? gi?ng h? : 1-B�i con tr?, ko b�t sao m� no ko d?ng l?i cho m�nh xem, m?c d� c� l?n getch(), v?i gi?i th�ch th�m d�m m�nh v? h�m malloc, alloc, khi n�o d�ng ,khi n�o ko, d�ng th� sao, ko th� sao ? CODE#include <stdio.h> #include #include <stdlib.h> main() { int *ptr; int var[]={1,2,3,4,5,6}; //ptr=(int *)malloc(6*sizeof(int)); ptr=var; for(int i=0;i<6;i++) printf("%5s",*(ptr+i)); free(ptr); getch(); } 2- B�i v? String, ch?ng hi?u l� l?i ji, m?c d� tr�n v?n d? ti?ng anh th� m�nh h?u r� n� n�i ji, b� tay th?t CODE#include <stdio.h> #include #include <string.h> main() { char word[10],string[10]; int n=0; printf("\nEnter a word(no space character) : "); scanf("%s",word); printf("\nThe word is : %s",word); printf("\nEnter a string(with space character) : "); do { scanf("%s",string[n]);

}while(strcmp(string[n++],'.')); printf("\nThe string is : "); for(int i=0;i #include #include <stdlib.h> main() { int *ptr; int var[]={1,2,3,4,5,6}; //ptr=(int *)malloc(6*sizeof(int)); ptr=var; for(int i=0;i<6;i++) printf("%5s",*(ptr+i)); free(ptr); getch(); } e e: � o + 1: � + 2 : � + 3 : ? + 4 : � + 5 : ? + 6 : � + 7 : o B?n n�n x�m l?i ph?n pointers v� memory. L�c b?n d�ng malloc h?a(c alloc d? t?o memory, c�i memory s? du?c t?o tr�n heap cho n�n b?n ph?i d�ng free() d? destroy v� tr? memory l?i cho heap, n?u ko b?n s? b? memory leak. T?i sao m�nh ko d�ng array h?t d? kh?i d�ng free() cho b?t phi?n ph?c? t?i v� ko ph?i l�c n�o m�nh bi?t m�nh s? d�ng bao nhi�u memory. N?u m�nh t?o nhi?u qu� m� ko d�ng th� ph�! C�n n?u t?o �t qu� th� m�nh l?i b? thi?u...cho n�n m�nh ph?i d�ng malloc v� pointers. C�n n?a, tuy C++ gi�p programmer v? pointer (l�m d? hon), nhung b?n ko n�n d�ng

C++ t?i v� v?y. B?n ko c?n d�ng dao khoai d? gi?t g� d�u! ...gi? t�i ph?i di r?i...d? l?n sau t�i tr?i l?i ph?n 2. Th�n camping29Jul 21 2008, 10:33 PM V? ph?n Malloc, alloc, realloc th� h?u r?i. Thx Lake 999 nha Theo � ki?n th� m�nh s? d?c qua C co b?n v� di ch? y?u v�o C++ , dang d?n ph?n H�m(Function), hi?n s?p c� 1 s? b�i t?p , sau d�y 1 b�i so so t? tui vi?t v? ph?n con tr? c? � vi?t = English cho quen ) CODE#include <stdio.h> #include main() {

int var,*ptr; printf("\nEnter value of variable var : ");scanf("%d",&var); ptr=&var;

printf("\nValue of variable var is : %d and var is stored at address %u",var,ptr); printf("\nValue of variable var ( using pointer ) is : %d",*ptr); printf("\nIncrement var by 1 : var = %d",++var); printf("\nDecrement var by 1 : var = %d",--var); printf("\nIncrement var by 1 ( using pointer ) : var = %d",++*ptr); printf("\nDecrement var by 1 ( using pointer ) : var = %d",--*ptr); *ptr++; printf("\nValue of the next interger after var is : %d and stored at addres %u.",*ptr,ptr); getch(); } - ptr = pointer var = var?able - B�i n�y ko sai, nhung cho h?i 1 c�i l�, n?u m�nh l?nh cu?i ), th� theo CT n� b�o ? bi?n d� du?c nh? *prt++), m� theo s�ch th� khi chuy?n t?i bi?n ti?p byte( v� ? d�y bi?n con tr? ptr dc khai b�o l� int sao ? d�y tang 4 byte ?

in s? nguy�n sau bi?n var( c�u sau v�ng nh? bi?n var 4 byte( theo th� n� ch? tang l�n 2 , m� int th� 2 byte nh? ), ch?

Related Documents

Sdg
July 2020 9
Sdg
June 2020 7
Essei Asignment Sdg
May 2020 8
Sdg Jiwa Lbm 5.docx
December 2019 22