มีโจทย์ว่าให้เรากรอกจำนวนข้อมูลที่จะใส่ แล้วใส่ค่าข้อมูลตามที่เรากรอก
แต่ปัญหาคือตัวข้อมูลที่เรากรอกนั้น ไม่ให้กด enter ให้กรอกข้อมูลยาวเลย
โดยใช้ spacebar ในการคั้นข้อมูลแต่ละตัว
ตัวอย่างครับ
จำนวนข้อมูล :3
ค่าข้อมูล :10 35 65
จำนวนข้อมูล :8
ค่าข้อมูล :1 2 3 4 5 6 7 8
เสร็จแล้วก็เอาค่าต่างๆไปคำนวณ
ไม่ทราบว่าจะรับค่าแบบนี้ใช้ scanf(); ได้มั้ย หรือต้องใช้อย่างอื่นครับ
ขอบคุณครับ
By crayon on
Tag:
Hiring! บริษัทที่น่าสนใจ
Carmen Software
Hotel Financial Solutions
Next Innovation (Thailand) Co., Ltd.
We are web design with consulting & engineering services driven the future stronger and flexibility.
KKP Dime
KKP Dime บริษัทในเครือเกียรตินาคินภัทร
Kiatnakin Phatra Financial Group
Financial Service
Fastwork Technologies
Fastwork.co เว็บไซต์ที่รวบรวม ฟรีแลนซ์ มืออาชีพจากหลากหลายสายงานไว้ในที่เดียวกัน
Thoughtworks Thailand
Thoughtworks เป็นบริษัทที่ปรึกษาด้านเทคโนโยลีระดับโลกที่คว้า Great Place to Work 3 ปีซ้อน
Iron Software
Iron Software is an American company providing a suite of .NET libraries by engineer for engineers.
CLEVERSE
Cleverse is a Venture Builder. Our team builds several tech companies.
Nipa Cloud
#1 OpenStack cloud provider in Thailand with our own data center and software platform.
Bangmod Enterprise
The leader in Cloud Server and Hosting in Thailand.
CIMB THAI Bank
MOVING FORWARD WITH YOU - CIMB is the leading ASEAN Bank
Bangkok Bank
Bangkok Bank is one of Southeast Asia's largest regional banks, a market leader in business banking
MuvMi (Urban Mobility Tech Co.,Ltd.)
Shape the future of urban mobility towards affordable, clean, and safe solutions
T.N. Digital Solution Co., Ltd.
TNDS has been involving in every first move of banking’s major digital transformation.
KBTG - KASIKORN Business-Technology Group
KBTG - "The Technology Company for Digital Business Innovation"
Siam Commercial Bank Public Company Limited
"Let's start a brighter career future together"
Icon Framework co.,Ltd.
Global Standard Platform for Real Estate แพลตฟอร์มสำหรับธุรกิจอสังหาริมทรัพย์ครบวงจร มาตรฐานระดับโลก
REFINITIV
The Financial and Risk business of Thomson Reuters is now Refinitiv
H LAB
Re-engineering healthcare systems through intelligent platforms and system design.
The Gang Technology Co., Ltd.
We're a Digital Agency that helps our customers transform their business into digital with ease.
LTMH
LTMH มุ่งเน้นการพัฒนาผลิตภัณฑ์ที่สามารถช่วยพันธมิตรของเราให้บรรลุเป้าหมาย
Seven Peaks
We Drive Digital Transformation
Wisesight (Thailand) Co., Ltd.
The Best Choice For Handling Social Media · High Expertise in Social Data · Most Advanced and Secure
MOLOG Tech
We are Modern Logistic Platform, Specialize in WMS, OMS and TMS.
Data Wow Co.,Ltd
We enable our clients to realize increased productivity by solving their most complex issues by Data
LINE Company Thailand
LINE, the world's hottest mobile messaging platform, offers free text and voice messaging + Call
LINE MAN Wongnai
Join our journey to becoming No.1 food platform in Thailand
ทำไมไม่ลองดูล่ะครับ?
nat3738 Tue, 29/07/2014 - 17:48
ทำไมไม่ลองดูล่ะครับ?
ลองดูแล้ว
crayon Tue, 29/07/2014 - 21:46
In reply to ทำไมไม่ลองดูล่ะครับ? by nat3738
ลองดูแล้ว หาอ่านตามที่ต่างๆแล้ว มันยังไม่ใช่อย่างที่ต้องการครับ
getc(); หรือ getch();
kswisit Tue, 29/07/2014 - 18:01
getc(); หรือ getch(); จำไม่ได้แล้ว - -a
จะลองหาข้อมูลดูครับ ขอบคุณครั
crayon Tue, 29/07/2014 - 21:48
In reply to getc(); หรือ getch(); by kswisit
จะลองหาข้อมูลดูครับ
ขอบคุณครับ
getch()
osmiumwo1f Tue, 29/07/2014 - 23:37
In reply to getc(); หรือ getch(); by kswisit
getch() มันรับแค่ตัวอักษรเดียวนะครับ
ไม่ทราบว่าจะรับค่าแบบนี้ใช้
Ginosty Tue, 29/07/2014 - 23:51
ไม่ทราบว่าจะรับค่าแบบนี้ใช้ scanf(); ได้มั้ย
ได้ครับ
จุดประสงค์ของโจทย์คือต้องการให้ฝึกการจัดการ String หรือฝึก while loop ครับ
ต้องเขียนโปรแกรมต่อนิดนึง
include
crayon Wed, 30/07/2014 - 11:42
#include "stdio.h"
main(void){
int a,b[100];
printf("จำนวนข้อมูล:");
scanf("%d",&a);
for(int i=0;i<a;i++){
printf("ค่าข้อมูล :");
scanf("%d",&b[i]);
}
}
โค๊ดที่ผมทดลองจะประมาณนี้ครับ แต่ถ้าใช้ scanf มันจะต้องกด enter
แต่ถ้าใช้วิธี scanf("%d %d %d %d %d",&b[0] &b[1] &b[2] &b[3] &b[4]);
ก็ไม่รู้อยู่ดีว่า จำนวนข้อมูลที่กรอกข้างบนเท่าไหร่ จะต้องใส่ใน scanf เท่าไหร่อยู่ดีครับ
scanf ไม่จำเป็นต้องกด enter
mix5003 Wed, 30/07/2014 - 15:00
In reply to include by crayon
scanf ไม่จำเป็นต้องกด enter นะครับ
เท่าที่เห็น code เกือบถูกแล้วครับ แต่ต้องย้าย printf ใน loop ออกนอก loop ครับ
แล้วลองเพิ่มอีก loop สั่ง print ค่าใน array ดูครับ
+1
McKay Wed, 30/07/2014 - 15:05
In reply to scanf ไม่จำเป็นต้องกด enter by mix5003
+1
ขอบคุณครับ
crayon Thu, 31/07/2014 - 00:34
In reply to scanf ไม่จำเป็นต้องกด enter by mix5003
ขอบคุณครับ เดี๋ยวพรุ่งนี้จะลองดูครับ