Aims. Our aim is to confirm the interstellar detection of cyanic acid, HOCN, in the Galactic center clouds. It has previously been tentatively detected only in Sgr B2(OH). Methods. We used a complete line survey of the hot cores Sgr B2(N) and (M) in the 3 mm range, complemented by additional observations carried out with the IRAM 30 m telescope at selected frequencies in the 2 mm band and towards four additional positions in the Sgr B2 cloud complex in the 2 and 3 mm bands. The spectral survey was analysed in the local thermodynamical equilibrium approximation (LTE) by modeling the emission of all identified molecules simultaneously. This allowed us to distinguish weak features of HOCN from the rich line spectrum observed in Sgr B2(...