007המקורי פורסם 2013 בינואר 8 מחבר Share פורסם 2013 בינואר 8 פיתאום זה עובד גם עם ה int ************************ מחרוזות (שאלה פשוטה) קלוט שם ושם מישפחה וצור מחרוזת נוספת המכילה שם פרטי ושם מישפחה. #include "stdafx.h"#include <stdio.h>#include <conio.h>#include <string.h>int main(){int name[20],last_name[20],total[50];printf ("enter your name!");gets(name);printf ("enter your last name!");gets(last_name);strcpy(total,name);strcat(total, " ");strcat(total,last_name);puts (total);getch();return 0;} קישור לתוכן שתף באתרים אחרים More sharing options...
007המקורי פורסם 2013 בינואר 8 מחבר Share פורסם 2013 בינואר 8 ---עוד שאלה קלילה----קלוט מחרוזת והדפס את אורכה. #include "stdafx.h"#include <stdio.h>#include <conio.h>#include <string.h>int main(){char word[100];int str;printf ("enter a word!(up to 50 letters) :");gets(word);str=strlen (word);printf(" the len of the `word` %d\n ",str);getch();return 0;} קישור לתוכן שתף באתרים אחרים More sharing options...
Gil28 פורסם 2013 בינואר 8 Share פורסם 2013 בינואר 8 אתה חייב לבחור שמות משמעותיים יותר.המשתנה str יכול להיקרא strLength או רק length.אגב, אם כבר ++C אז תשתמש ב-()cin.get ולא ב-()getch קישור לתוכן שתף באתרים אחרים More sharing options...
007המקורי פורסם 2013 בינואר 8 מחבר Share פורסם 2013 בינואר 8 עברתי ל c (אני מקודד עכשיו ב C). קישור לתוכן שתף באתרים אחרים More sharing options...
שניצל פורסם 2013 בינואר 8 Share פורסם 2013 בינואר 8 cin.get זה לא אותו דבר כמו getch... הראשון קורא תו מהbuffer והשני קורא ישירות מהמקלדת. קישור לתוכן שתף באתרים אחרים More sharing options...
007המקורי פורסם 2013 בינואר 9 מחבר Share פורסם 2013 בינואר 9 קלוט שני מחרוזות ובדוק אם הם זהות. #include "stdafx.h"#include <stdio.h>#include <conio.h>#include <string.h>#include <stdlib.h>int main(){char name[50],name_2[50];int calculus_cmp=0;printf ("enter your name!(up to 40 letters)");gets (name);printf("enter another name!(up to 40 letters)");gets (name_2);calculus_cmp= strcmp(name,name_2);if (calculus_cmp == 0){printf("the names are the same!");}elseprintf("the names are not the same!");getch();return 0;} קישור לתוכן שתף באתרים אחרים More sharing options...
Gil28 פורסם 2013 בינואר 9 Share פורסם 2013 בינואר 9 למה לשמור את הערך שמחזירה הפונקציה strcmp ולא ישר לבצע בדיקה עליו? לדוגמא:if (strcmp(name1,name2)){ printf("the names are different");}else{ printf("the names are identical");} קישור לתוכן שתף באתרים אחרים More sharing options...
Recommended Posts
ארכיון
דיון זה הועבר לארכיון ולא ניתן להוסיף בו תגובות חדשות.