我正在尝试打印出电话号码,但出现错误

时间:2019-02-04 13:16:24

标签: c arrays

只是为了让大家都知道编程方面的新知识,我想我只是想念一些小东西,但我不知道它是什么。编译代码时,出现此错误“格式%d期望匹配的int自变量[-Wformat=]”。我已经尝试了很多东西。我尝试将所有函数类型都设置为char,并将它们全部都设置为int。我收到类似的错误。

char *phoneInput(void)
{
    char phone[11];

    printf("Input the politicians phone number with no spaces: ");
    fgets(phone, 10, stdin);
    return 0;
}

char  printPhone(char phone[11])
{
    printf("- Phone Number: (%d%d%d)%d%d%d-%d%d%d%d", phone[0], phone[1], phone[2], 
              phone[3], phone[5], phone[6], phone[7], phone[8], phone[9]);

    return 0;
}

1 个答案:

答案 0 :(得分:1)

您的// Event struct type Event struct { Name string Data interface{} } // Stream to publish events to var stream = make(chan *Event, 100) // Publish sends new event data to the stream by the event name func Publish(name string, data interface{}) { ev := &Event{name, data} stream <- ev } // Handler provides the interface for all event handlers. // The Work will be called with the event that it should process type Handler interface { Work(*Event) } type worker struct { Handler Listen chan *Event Quit chan bool } // Stop shuts down the worker func (w *worker) Stop() { go func() { w.Quit <- true }() } // Queue of worker Listen channels type workerQueue chan chan *Event // registry of workers var registry = make(map[string][]workerQueue) // Register creates 20 workers, assigns them to a queue, and // appends the resulting worker queue to an event on the handler registry func Register(name string, handlers ...Handler) { if _, ok := registry[name]; !ok { registry[name] = make([]workerQueue, 0) } // Create workerQueues for each handler for _, h := range handlers { queue := make(workerQueue, numListeners) // Create 20 workers for i := 0; i < 20; i++ { newWorker := worker{ Handler: h, Listen: make(chan *Event), Quit: make(chan bool), } go func() { for { select { case ev := <-newWorker.Listen: nl.Work(ev) case <-newWorker.Quit: return } } }() queue <- newWorker.Listen } registry[name] = append(registry[name], queue) } } // Start begins listening for events on stream func Start() { go func() { for { select { // listen for events case ev := <-stream: go func() { // get registered queues for the event queues, ok := registry[ev.Name] if !ok { return } // Get worker channel from queue and send the event for _, queue := range queues { worker := <-queue worker <- ev } }() } } }() } 语句缺少一个参数。像这样将// Usage Start() type demoHandler struct { db *sql.DB } type eventData struct {} func (h *demoHandler) Work(ev *Event) { // Do something return } // Register handler Register('some-event', &demoHandler{r}) Publish('some-event', &eventData{}) 添加到您的printf

phone[4]

但是我不明白,为什么实际上所有两个函数都只返回printf,所以为什么所有函数的返回类型都是#include <iostream> using namespace std; char *phoneInput(void) { char phone[11]; printf("Input the politicians phone number with no spaces: "); fgets(phone, 10, stdin); return 0; } char printPhone(char phone[11]) { printf("- Phone Number: (%d%d%d)%d%d%d-%d%d%d%d", phone[0], phone[1], phone[2], phone[3], phone[4], phone[5], phone[6], phone[7], phone[8], phone[9]); return 0; } char*。 / p>